Click here to Skip to main content
11,709,220 members (72,323 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# list
is this possible list<int,string>?
Posted 1-Mar-13 7:20am
Comments
Sergey Alexandrovich Kryukov at 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 at 1-Mar-13 14:03pm
   
list=new list; collection.
Sergey Alexandrovich Kryukov at 1-Mar-13 14:18pm
   
I answered, and Solution 1 may be the option, but... there are no "columns" notion here...
—SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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:

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
  Permalink  
v4
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

If you want a List consisting of an integer key with a string value, then you would use Dictionary<int,string>.
  Permalink  
Comments
Sergey Alexandrovich Kryukov at 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 at 6-Mar-13 6:39am
   
how to Dictionary?

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 565
1 OriginalGriff 244
2 Maciej Los 225
3 Peter Leow 219
4 Mika Wendelius 160
0 OriginalGriff 9,348
1 Sergey Alexandrovich Kryukov 8,727
2 CPallini 5,189
3 Maciej Los 4,991
4 Mika Wendelius 3,856


Advertise | Privacy | Mobile
Web03 | 2.8.150819.1 | Last Updated 1 Mar 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100