Reputation: 678
how do we create a list with multiple values for example , list[0] contains three values {"12","String","someValue"} the Some value is associated to the two other values i want to use a list rather than using an array
string[, ,] read = new string[3, 3, 3];
Upvotes: 7
Views: 52165
Reputation: 3731
How about using a Lookup<TKey,TElement>
?
From MSDN:
A Lookup resembles a Dictionary. The difference is that a Dictionary maps keys to single values, whereas a Lookup maps keys to collections of values.
Upvotes: 3
Reputation: 25056
Why not have a List
of Tuple
's? It can be unclear, but it will do what you are after:
var list = new List<Tuple<string, string, string>>();
list.Add(new Tuple<string, string, string>("12", "something", "something"));
Although it would probably be better to give these values semantic meaning. Perhaps if you let us know what the values are intending to show, then we can give some ideas on how to make it much more readable.
Upvotes: 17
Reputation: 214
Or you can make a separate class that will contain all the values. Let's call this class Entity:
class Entity{int i; String s; Object SomeValue;}
and then just do
List<Entity> list=new List<Entity>()
Alternatively you can use a matrix.
Upvotes: 0
Reputation: 11025
You could use Tuple
:
List<Tuple<String, String, String>> listOfTuples = new List<Tuple<String, String, String>>();
listOfTuples.Add(new Tuple<String, String, String>("12", "String", "someValue"));
The MSDN:
Upvotes: 3
Reputation: 56688
Use list of lists:
List<List<string>> read;
Or if you want key-multiple values relation, use dictionary of lists:
Dictionary<string, List<string>> read;
Upvotes: 6