Is there a way in C# to initialize jagged arrays similarly as in Java -
in java, can following:
string[][] map = { {"1.0, ", "1.1, ", "1.2, ", "1.3, ", "1.0, "}, {"a, ", "b, ", "c, ", "d, ", "e, "}, {"x, ", "xx, ", "xxx, ", "xxxx, ", "xxxx, "}, };
but same code not compile in c#. in tedious way initializing sub-fields 1 one sure there better way.
the closest thing can in c#
add new []
before each array initializer:
string[][] map = { new [] {"1.0, ", "1.1, ", "1.2, ", "1.3, ", "1.0, "}, new [] {"a, ", "b, ", "c, ", "d, ", "e, "}, new [] {"x, ", "xx, ", "xxx, ", "xxxx, ", "xxxx, "}, };
Comments
Post a Comment