Passing arrays to seperate class files

  • Thread starter Thread starter David
  • Start date Start date
D

David

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
 
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
 
Back
Top