Storing an array of a different type into a jagged array

前提是你 提交于 2019-12-08 00:44:03

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!