Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which collection should I use?

I'm looking for the ideal collection to use in my current situation.

All I need is a List<string> which can allow two entries for each index. Similar to a Dictionary, however I do not need keys and values, and would like to iterate through it by index. The best collection I can think of is a multi-dimension array, however I would like to specify that two items can be stored in each element, however the amount of elements can be infinite.

Which collection should I use?

EDIT: Also, I thought of using a List<List<string>>, however since I only need two elements for each index, I think storing a list in each index position of the list would be a waste.

like image 228
Dot NET Avatar asked Dec 10 '25 13:12

Dot NET


2 Answers

You can use Tuple

Check this: Tuple (Class)

var population = new Tuple<string, string>("New York", "Madrid");
like image 106
Carlos Landeras Avatar answered Dec 12 '25 01:12

Carlos Landeras


Try use a class

public class MyData
{
    public string Data1 {get;set;}
    public string Data2 {get;set;}
}

var obj = List<MyData>();
like image 26
John Kenedy Avatar answered Dec 12 '25 03:12

John Kenedy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!