Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Array of string pairs

Tags:

arrays

c#

How do I generate the array of string pairs? I need it to quickly initialize it with static data.

stringPair[] arr = {{"hgh","hjhjh"},{"jkjk","kjhk"}
like image 275
Yakov Avatar asked Dec 03 '22 20:12

Yakov


2 Answers

You can use list/array Tuple Class

Example

List<Tuple<string, string>> data = new List<Tuple<string, string>>{
        new Tuple<string, string>("Hello", "World"),
        new Tuple<string, string>("Foo", "Bar")
    };

As per @Eric Lippert's comment, Use Tuple.Create

List<Tuple<string, string>> data = new List<Tuple<string, string>>{
        Tuple.Create("Hello", "World"),
        Tuple.Create("Foo", "Bar")
    };
like image 153
Satpal Avatar answered Dec 13 '22 04:12

Satpal


You can do something like this using mulitdimentional array:

string[,] arr = new string[,]{{"hgh","hjhjh"},{"jkjk","kjhk"}};
like image 40
Andrei Avatar answered Dec 13 '22 03:12

Andrei