G
Guest
How can you get a custom struct to work with the "in" and "as" keywords, for
example, (myObject is myStruct).....see full code example below....
private void CreateArray(ArrayList myArray)
{
ArrayList newArray= new ArrayList();
foreach (object item in myArray)
{
if (item is myStruct) //this doesn't work, myStruct is a
ValueType
{
newArray.Add(new exampleType1
(item as myStruct)); //this doesn't work, myStruct
is a ValueType
}
else if (item is anotherStruct)
{
newArray.Add(new exampleType2
(item as anotherStruct));
}
}
}
example, (myObject is myStruct).....see full code example below....
private void CreateArray(ArrayList myArray)
{
ArrayList newArray= new ArrayList();
foreach (object item in myArray)
{
if (item is myStruct) //this doesn't work, myStruct is a
ValueType
{
newArray.Add(new exampleType1
(item as myStruct)); //this doesn't work, myStruct
is a ValueType
}
else if (item is anotherStruct)
{
newArray.Add(new exampleType2
(item as anotherStruct));
}
}
}