user3859922
user3859922

Reputation:

Storing an array of a different type into a jagged array

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?

Upvotes: 4

Views: 2416

Answers (1)

lame_coder
lame_coder

Reputation: 3115

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.

Upvotes: 4

Related Questions