>I haven't worked with arrays yet, so I'm not familiar with the syntax. I was wondering if this can be defined differently. Like in VFP, where you define the array first, then fill it. Something like this maybe? It would definitely be more readable if you could ...
>
>object[,] oArray = new object(something here?);
>oArray[1,1] = 4
>oArray[1,2] = "Claudio";
>
>etc.
>
>
>~~Bonnie
>
Yes, there is a couple of way to declare and dimension arrays in C#.
I use the one you suggest in the sample that follow.
For the Multiple type array problem submit by Claudio,
I suggest the use of an array of structure witch is better OOP and easier to use than the previous solution.
Just create a simple structure to hold a line of different types
and a method to assign values to fields.
Now you can create an array of this new type and use the method to assign the values.
You can access each fields by the name instead of relying on a second level index.
class Class1
{
struct PERSONS{
public string name;
public int age;
public void assign(string n, int a)
{
name=n;
age=a;
}
}
[STAThread]
static void Main(string[] args)
{
PERSONS[] persons= new PERSONS[4];
persons[0].assign("Claudio",32);
persons[1].assign("Michel",39);
persons[2].assign("Max",25);
persons[3].assign("Mike",29);
for (int i=0; i<4; i++)
{
System.Console.WriteLine(persons[i].name);
System.Console.WriteLine(persons[i].age);
}
}
}
HTH :-)
If we exchange an apple, we both get an apple.
But if we exchange an idea, we both get 2 ideas, cool...Gérald Santerre
Independant programmer - internet or intranet stuff - always looking for contracts big or small :)
http://www.siteintranet.qc.ca