A function returns an object, with an object member filled with an anonymous array of items; how do I get back the individual items?
the object that is returned from a function:
public class FunctionCallResult
{
...blah blah members...
public object ResultObject { get; set; }
}
The function:
FunctionCallResult SomeCrazyFunction(string irrelevant_param1, int some_other_irrelevant_param2)
{
... some heavy duty code that raises eyebrows ...
return new FunctionCallResult{ new object[] { SomeCrazyClassX, AnotherCraxyClassY } };
}
An example call of function:
var myresult = SomeCrazyFunction( "I am the walrus", 42);
But now, how do I get back the individual objects, which are of different classes?
// can't do this... can't index type of object
SomeCrazyClassXType classX = myresult.ResultObject[0];
AnotherCraxyClassYType classY = myresult.ResultObject[1];
So...how can I get these different class types out of the result returned?
var t = new { A=1, B=2 };[]. see this for syntax An anonymous type is not bound to a name.* Your array doesn't have an anonymous type. It's type is Object. There may be a boxing or reference conversion involved, but the array is still composed of named types. (Note from above: the anonymous type has a name, but the compiler doesn't tell you what it is directly, and you can't use it to instantiate the type.)