Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
is this possible list<int,string>?
Posted
Updated 12-Feb-17 22:00pm
Comments
Sergey Alexandrovich Kryukov 1-Mar-13 13:24pm    
What is list, exactly? If it UI? Or just a collection? If it is, tag the UI library.
—SA
scorpzonex 1-Mar-13 14:03pm    
list<int>=new list<int>; collection.
Sergey Alexandrovich Kryukov 1-Mar-13 14:18pm    
I answered, and Solution 1 may be the option, but... there are no "columns" notion here...
—SA

We don't know how you want to use such collection: for access by key (then see Solution 1), or as list. If as list, create a structure or a class, for example:

C#
struct ListElement {
   public int Id,
   public string Name,
}

// ...

List<ListElement> list = new List<ListElement>();


[EDIT]

Another option is using the tuple: http://msdn.microsoft.com/en-us/library/system.tuple.aspx[^].

—SA
 
Share this answer
 
v4
If you want a List consisting of an integer key with a string value, then you would use Dictionary<int,string>.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 1-Mar-13 14:13pm    
I voted 4, because we really don't know if OP wants to use access by key. Maybe it still have to be a list, then the solution is the list of struct/class instance.
Please see my answer (which of course credits yours).
—SA
scorpzonex 6-Mar-13 6:39am    
how to Dictionary<int,string,string,string>?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900