473,396 Members | 1,866 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Passing arrays to seperate class files

Hi all,

I am fairly new to C#. so go easy on me :-)

Anyhow, I have a class file that I have set up properties and a method.

I am calling this class file directly from and aspx.cs file. So far, it
works great (after having a bit of heartache about .Dispose() ).

Now, I need a certain part of the class file to run through many times and
take values from an array/arraylist/dataset (which ever is the easiest).

What I need to pass is:
1. An array of filenames. (could be about 5 or 6 different filenames.)
2. An array of x,y coordinates. (Up to 73 coordinates)
3. An array of tying filenames to x,y coords.

(number 3 may be able to integrate into 1 or 2, but I am not sure how to go
about it).

What I don't know is wether to set up properties and pass the arrays to the
properties OR pass the arrays direct into the method.

Either way, can someone show me how to handle it?

What I want to do though is to not be forced to use an array when calling
the method, so that I can use my existing properties if need be to set the
method up. I think this is going to lead me down override/inheritence (never
done that before...) in order to be able to use both.

So, in summary, here is what I need to do...

Call my program like...
myClass.MyMethod().save(...)

or
myClass.MyMethod(array1, array2, array3).save(...)

Any and all help will be very much appreciated.

Thanks.
Dave Colliver.
http://www.GreatYarmouthFOCUS.com
~~
http://www.FOCUSPortals.com - Portal Franchises available

Nov 17 '05 #1
2 2233
David,

I find what your trying to do pretty hard to grasp, but I'm guessing
that you want to some arrays into a class / method and class an
interative process on it.

Lets assume for this example than you have N filenames and want to draw
X coordinates on them, for each one making a file. You will only need
two arrays.

Firtly there the two most basic ways of handling arrays are either using
an arraylist of an type[] array. Lets go with arraylists for now as they
are easier as they are dynamic in size (type[] arrays are fixed)

From you calling method you need to build the arraylists.

public void CallingMethod() {
ArrayList filesArray = new ArrayList();
ArrayList pointsArray = new ArrayList();

// Build an arraylist of files
foreach(string file in Directory.GetFiles(somePath))
{
filesArray.Add(file);
}

// Build some points using some method
for(int i = 0; i < 20; i++)
{
for(int j = 0; j < 10; j++)
{
pointsArray.Add(new Point(i, j));
}
}
}

This will build up two array list objects, now lets say you have a Class
called DrawingMagic that creates all your files, after the two loops in
CallingMethod() we can add this.

DrawingMagic dm = new DrawingMagic();
DrawingMagic.Process(filesArray, pointsArray).

The process method in DrawingMagic would look something like this.

NOTE: An assumption has been made that all files will use ALL points.

class DrawingMagic
{
// ...
public void Process(Arraylist files, Arraylist points)
{
foreach(string file in files)
{
foreach(Point point in points)
{
Bitmap b =
this.CallDrawingMethod(file, point);
b.Save(String.Format("{0}{1}{2}.jpg",
Path.GetWithNameWithoutExtention(file), point.X, point.Y),
ImageFormat.Jpeg);
}
}
}
}

The this.CallDrawingMethod() accepts a single string for the file and a
single Point object for the point, and in this case returns a bitmap
object. Then the bitmap is saved using a combination of the file name
and point name.

Hope this helps

David wrote:
Hi all,

I am fairly new to C#. so go easy on me :-)

Anyhow, I have a class file that I have set up properties and a method.

I am calling this class file directly from and aspx.cs file. So far, it
works great (after having a bit of heartache about .Dispose() ).

Now, I need a certain part of the class file to run through many times and
take values from an array/arraylist/dataset (which ever is the easiest).

What I need to pass is:
1. An array of filenames. (could be about 5 or 6 different filenames.)
2. An array of x,y coordinates. (Up to 73 coordinates)
3. An array of tying filenames to x,y coords.

(number 3 may be able to integrate into 1 or 2, but I am not sure how to go
about it).

What I don't know is wether to set up properties and pass the arrays to the
properties OR pass the arrays direct into the method.

Either way, can someone show me how to handle it?

What I want to do though is to not be forced to use an array when calling
the method, so that I can use my existing properties if need be to set the
method up. I think this is going to lead me down override/inheritence (never
done that before...) in order to be able to use both.

So, in summary, here is what I need to do...

Call my program like...
myClass.MyMethod().save(...)

or
myClass.MyMethod(array1, array2, array3).save(...)

Any and all help will be very much appreciated.

Thanks.
Dave Colliver.
http://www.GreatYarmouthFOCUS.com
~~
http://www.FOCUSPortals.com - Portal Franchises available

Nov 17 '05 #2
David,

I find what your trying to do pretty hard to grasp, but I'm guessing
that you want to some arrays into a class / method and class an
interative process on it.

Lets assume for this example than you have N filenames and want to draw
X coordinates on them, for each one making a file. You will only need
two arrays.

Firtly there the two most basic ways of handling arrays are either using
an arraylist of an type[] array. Lets go with arraylists for now as they
are easier as they are dynamic in size (type[] arrays are fixed)

From you calling method you need to build the arraylists.

public void CallingMethod() {
ArrayList filesArray = new ArrayList();
ArrayList pointsArray = new ArrayList();

// Build an arraylist of files
foreach(string file in Directory.GetFiles(somePath))
{
filesArray.Add(file);
}

// Build some points using some method
for(int i = 0; i < 20; i++)
{
for(int j = 0; j < 10; j++)
{
pointsArray.Add(new Point(i, j));
}
}
}

This will build up two array list objects, now lets say you have a Class
called DrawingMagic that creates all your files, after the two loops in
CallingMethod() we can add this.

DrawingMagic dm = new DrawingMagic();
DrawingMagic.Process(filesArray, pointsArray).

The process method in DrawingMagic would look something like this.

NOTE: An assumption has been made that all files will use ALL points.

class DrawingMagic
{
// ...
public void Process(Arraylist files, Arraylist points)
{
foreach(string file in files)
{
foreach(Point point in points)
{
Bitmap b =
this.CallDrawingMethod(file, point);
b.Save(String.Format("{0}{1}{2}.jpg",
Path.GetWithNameWithoutExtention(file), point.X, point.Y),
ImageFormat.Jpeg);
}
}
}
}

The this.CallDrawingMethod() accepts a single string for the file and a
single Point object for the point, and in this case returns a bitmap
object. Then the bitmap is saved using a combination of the file name
and point name.

Hope this helps

David wrote:
Hi all,

I am fairly new to C#. so go easy on me :-)

Anyhow, I have a class file that I have set up properties and a method.

I am calling this class file directly from and aspx.cs file. So far, it
works great (after having a bit of heartache about .Dispose() ).

Now, I need a certain part of the class file to run through many times and
take values from an array/arraylist/dataset (which ever is the easiest).

What I need to pass is:
1. An array of filenames. (could be about 5 or 6 different filenames.)
2. An array of x,y coordinates. (Up to 73 coordinates)
3. An array of tying filenames to x,y coords.

(number 3 may be able to integrate into 1 or 2, but I am not sure how to go
about it).

What I don't know is wether to set up properties and pass the arrays to the
properties OR pass the arrays direct into the method.

Either way, can someone show me how to handle it?

What I want to do though is to not be forced to use an array when calling
the method, so that I can use my existing properties if need be to set the
method up. I think this is going to lead me down override/inheritence (never
done that before...) in order to be able to use both.

So, in summary, here is what I need to do...

Call my program like...
myClass.MyMethod().save(...)

or
myClass.MyMethod(array1, array2, array3).save(...)

Any and all help will be very much appreciated.

Thanks.
Dave Colliver.
http://www.GreatYarmouthFOCUS.com
~~
http://www.FOCUSPortals.com - Portal Franchises available

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Bryan Martin | last post by:
I have a object that is created in a seperate domain which needs to be passed back to the parent class. Because this object is created in a seperate domain if I try to pass the object back to the...
13
by: muser | last post by:
for the following code: strncpy(temp_issue, &temp1, 4); files.rec1.issue_rec = atol(temp_issue); cout<<files.rec1.issue_rec<<endl; on execution I get the following. 0x0fd10 a memory...
58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
9
by: justanotherguy63 | last post by:
Hi, I am designing an application where to preserve the hierachy and for code substitability, I need to pass an array of derived class object in place of an array of base class object. Since I...
0
by: David | last post by:
Hi all, I am fairly new to C#. so go easy on me :-) Anyhow, I have a class file that I have set up properties and a method. I am calling this class file directly from and aspx.cs file. So...
3
by: Mark | last post by:
Hi From what I understand, you can pass arrays from classic ASP to .NET using interop, but you have to change the type of the.NET parameter to object. This seems to be because classic ASP passes...
1
by: Doug_J_W | last post by:
I have a Visual Basic (2005) project that contains around twenty embedded text files as resources. The text files contain two columns of real numbers that are separated by tab deliminator, and are...
17
by: =?Utf-8?B?U2hhcm9u?= | last post by:
Hi Gurus, I need to transfer a jagged array of byte by reference to unmanaged function, The unmanaged code should changed the values of the array, and when the unmanaged function returns I need...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.