I try to add a string array to a list of string arrays
I tried list.add but didnt work
List<string[,]> stringList=new List<string[,]>();
stringList.Add({"Vignesh","26"},{"Arul","27"});
Are you sure you need more than 1 dimension in the inner arrays?
List<string[]> stringList = new List<string[]>(); // note just [] instead of [,]
stringList.Add(new string[] { "Vignesh", "26" } );
stringList.Add(new string[] { "Arul", "27" } );
or
List<string[]> stringList = new List<string[]>
{
new string[] { "Vignesh", "26" }
new string[] { "Arul", "27" }
};
If yes then:
List<string[,]> stringList = new List<string[,]>();
stringList.Add(new string[,] { { "Vignesh" }, { "26" } } );
stringList.Add(new string[,] { { "Arul" }, { "27" } } );
or
List<string[,]> stringList = new List<string[,]>
{
new string[,] { { "Vignesh" }, { "26" } },
new string[,] { { "Arul" }, { "27" } }
};
But I'd rather have a custom type:
class Person
{
public string Name { get; set; }
public int Age { get; set; } // or of type string if you will
}
List<Person> personList = new List<Person>
{
new Person { Name = "Vignesh", Age = 26 }
};
You need to create rectangular array but you are trying to pass single dimensional array of strings instead of rectangular array.
List<string[,]> stringList=new List<string[,]>();
stringList.Add(new string[,] {{"Vignesh","26"},{"Arul","27"}});