问题
Does an array stored inside a jagged array need to be of the same type? for example can I store an array of ints and an array of strings in one jagged array?
回答1:
Why not use an array of objects ? here is an example-
var jaggedArray = new object[3];
jaggedArray[0] = new[] { 1, 2, 3 };
jaggedArray[1] = new[] { "str", "onemore" };
jaggedArray[2] = new[] { new { prop = 14 }, new { prop = 12 }, new { prop = 1 } };
Console.Write(jaggedArray[0].ToString());
Copy & paste this in a console application and have a breakpoint on Console.Write, you can see the built array in quick watch window.
来源:https://stackoverflow.com/questions/25091947/storing-an-array-of-a-different-type-into-a-jagged-array