Jag Arrays
-
I don't think so.. because you're declaring an array that holds arrays of a certian type. I think you're going to want an object or a struct. I'm guessing a stuct is going to be more suited to what you need. Example..
using System;
class MyApp
{
static void Main() {
myStruct testVar = new myStruct();
testVar.intArray = new int[] {1,2,3};
testVar.strArray = new String[] {"One", "Two", "Three"};Console.WriteLine("{0} - {1}", testVar.intArray\[2\], testVar.strArray\[2\]); } struct myStruct { public int\[\] intArray; public string\[\] strArray; };
}
structs are going to be faster than objects. But if you want to iterate through members, you should create an object that can be used with a "foreach" loop.
-
It is possible, there is on cavet though. If one of your datatypes is a ValueType (ie, you can't set it to null) an exception will be thrown when you do a foreach on the array.
object [] test = new object[2];
test[0] = new string[4];
test[1] = new Type[2];int j;
for(j = 0; j < 4; j++)
{
((string[]) test[0])[j] = "moo" + j.ToString();
}((Type[]) test[1])[0] = typeof(object);
((Type[]) test[1])[1] = typeof(System.Guid);foreach(object [] t in test)
{
foreach( object i in t )
{
Console.Write("{0}, ", i);
}
Console.WriteLine("");
}Console.ReadLine();
Sorry for the horrible formatting, the pre tag seems to be taking out all blank lines :( James Sonork ID: 100.11138 - Hasaki "Not be to confused with 'The VD Project'. Which would be a very bad pr0n flick. :-D" - Michael P Butler Jan. 18, 2002
-
It is possible, there is on cavet though. If one of your datatypes is a ValueType (ie, you can't set it to null) an exception will be thrown when you do a foreach on the array.
object [] test = new object[2];
test[0] = new string[4];
test[1] = new Type[2];int j;
for(j = 0; j < 4; j++)
{
((string[]) test[0])[j] = "moo" + j.ToString();
}((Type[]) test[1])[0] = typeof(object);
((Type[]) test[1])[1] = typeof(System.Guid);foreach(object [] t in test)
{
foreach( object i in t )
{
Console.Write("{0}, ", i);
}
Console.WriteLine("");
}Console.ReadLine();
Sorry for the horrible formatting, the pre tag seems to be taking out all blank lines :( James Sonork ID: 100.11138 - Hasaki "Not be to confused with 'The VD Project'. Which would be a very bad pr0n flick. :-D" - Michael P Butler Jan. 18, 2002
-
It is possible, there is on cavet though. If one of your datatypes is a ValueType (ie, you can't set it to null) an exception will be thrown when you do a foreach on the array.
object [] test = new object[2];
test[0] = new string[4];
test[1] = new Type[2];int j;
for(j = 0; j < 4; j++)
{
((string[]) test[0])[j] = "moo" + j.ToString();
}((Type[]) test[1])[0] = typeof(object);
((Type[]) test[1])[1] = typeof(System.Guid);foreach(object [] t in test)
{
foreach( object i in t )
{
Console.Write("{0}, ", i);
}
Console.WriteLine("");
}Console.ReadLine();
Sorry for the horrible formatting, the pre tag seems to be taking out all blank lines :( James Sonork ID: 100.11138 - Hasaki "Not be to confused with 'The VD Project'. Which would be a very bad pr0n flick. :-D" - Michael P Butler Jan. 18, 2002