I have a list of names which is static. I want to save it in a an static jaggedArray (to avoid multiple copies of same data).
I want to write something like below code
public static string[][] nameList = new string[10][] [{"name1_1","name1_2"},{"name2_1","name2_2"},{"name3_1","name3_2"}....]; but C# is not allowing above code. My current code is written as (given below), but for each call it is creatinga a new object
public static string[][] GetNameList() { string[][] nameList = new string[10][]; nameList [0] = new string[] { "name1_1", "name1_2" }; nameList [1] = new string[] { "name2_1", "name2_2" }; nameList [2] = new string[] { "name3_1", "name3_2" }; ............ return nameList; } In above method, the returned object is not static. Can you please help me to create static object. Thanks in advance
Edit : finally got the solution or you can say got the correct syntax ....
public static readonly string[,] UserList = new string[10, 2] { { "UsersId0_0", "UsersId0_1" }, { "UsersId1_0", "UsersId1_1" }.... };
static readonly IReadOnlyList<IReadOnlyList<string>>as the signature. Otherwise someone might either replace the entire array, or elements inside the array.