F
farseer
Hi,
suppose i have an array of two different class types.
TypeA[] array1;
TypeB[] array2;
Now supposing both TypeA and TypeB contain a property called "id"
(they, do not inherit from a common base class or interface, that just
happens to be the method name).
I'd like to be able to pass either array to a method and call the "id"
method. for instance,
...
processArray( array1 ); //array contain objects of TypeA
processArray( array2 ); //array contain objects of TypeB
...
public void processArray( Object[] arr )
{
for( int i = 0; i < arr.Length; i++ )
{
System.Console.WriteLine("Value: " + arr[ i ].id);
}
}
How can i do this?
suppose i have an array of two different class types.
TypeA[] array1;
TypeB[] array2;
Now supposing both TypeA and TypeB contain a property called "id"
(they, do not inherit from a common base class or interface, that just
happens to be the method name).
I'd like to be able to pass either array to a method and call the "id"
method. for instance,
...
processArray( array1 ); //array contain objects of TypeA
processArray( array2 ); //array contain objects of TypeB
...
public void processArray( Object[] arr )
{
for( int i = 0; i < arr.Length; i++ )
{
System.Console.WriteLine("Value: " + arr[ i ].id);
}
}
How can i do this?