473,763 Members | 6,638 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.MyMetho d().save(...)

or
myClass.MyMetho d(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 2257
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.GetFi les(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.Pr ocess(filesArra y, 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(Arrayli st files, Arraylist points)
{
foreach(string file in files)
{
foreach(Point point in points)
{
Bitmap b =
this.CallDrawin gMethod(file, point);
b.Save(String.F ormat("{0}{1}{2 }.jpg",
Path.GetWithNam eWithoutExtenti on(file), point.X, point.Y),
ImageFormat.Jpe g);
}
}
}
}

The this.CallDrawin gMethod() 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.MyMetho d().save(...)

or
myClass.MyMetho d(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.GetFi les(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.Pr ocess(filesArra y, 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(Arrayli st files, Arraylist points)
{
foreach(string file in files)
{
foreach(Point point in points)
{
Bitmap b =
this.CallDrawin gMethod(file, point);
b.Save(String.F ormat("{0}{1}{2 }.jpg",
Path.GetWithNam eWithoutExtenti on(file), point.X, point.Y),
ImageFormat.Jpe g);
}
}
}
}

The this.CallDrawin gMethod() 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.MyMetho d().save(...)

or
myClass.MyMetho d(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
1902
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 parent class (different domain) I receive an error about "File Not Found". I know the object is created successfully and the objects method can be called after loading the object however upon passing it back to the calling class it exploades. I...
13
2244
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 address no doubt.
58
10179
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 code... TCHAR myArray; DoStuff(myArray);
9
4804
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 am using vector class(STL), the compiler does not allow me to do this. I do realize there is a pitfall in this approach(size of arrays not matching etc), but I wonder how to get around this problem. I have a class hierachy with abstract base...
0
307
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 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
3
3794
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 a variant containing an array, and interop expects a parameter of type object if you are passing a variant (you are expected to cast it to the correct type in your code). I'd like to find a way of passing arrays so that you don't need to change...
1
2449
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 of different lengths (e.g. usually between 25 and 45 rows. The columns in each file have the same length). The text files have been numbered sequentially e.g. cb0, cb1, cb2 and so on. I would like to read the data from each text file into...
17
7253
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 to show the array data to the end user. Can I do that? How?
0
9564
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9387
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10148
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10002
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8822
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7368
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6643
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5270
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.