I often need one key to multiple vaules dictionary, but in C# most of them are two dimensions like Dictionary and Hashtable.  I want something like this:  var d = new Dictionary&lt;key-dt,value1-dt,value2-dt,value3-dt,value4-dt&gt;();   dt inside&lt;> means data type. Anybody has ideas about this?
72597
How would i create a multi value Dictionary in c#?  E.g. Dictionary&lt;T,T,T&gt; where the first T is the key and other two are values.  so this would be possible: Dictionary&lt;int,object,double&gt;  Thanks
1436
Imagine that you have the following list. keys = ['name', 'age', 'food'] values = ['Monty', 42, 'spam']  What is the simplest way to produce the following dictionary? a_dict = {'name': 'Monty', 'age': 42, 'food': 'spam'}
15230
example:  public static void DoSomething&lt;K,V&gt;(IDictionary&lt;K,V&gt; items) {    items.Keys.Each(key =&gt; {       if (items[key] **is IEnumerable&lt;?&gt;**) { /* do something */ }       else { /* do something else */ } }   Can this be done without using reflection? How do I say IEnumerable in C#? Should I just use IEnumerable since IEnumerable&lt;> implements IEnumerable?
70797
I was shocked to find out today that C# does not support dynamic sized arrays. How then does a  developer used to using  deal with this in C#?  At the beginning of the function I am not sure of the upper bound of the array. This depends on the rows returned from the database.
44281
I often have to sort a dictionary, consisting of keys &amp; values, by value. For example, I have a hash of words and respective frequencies, that I want to order by frequency.  There is a SortedList which is good for a single value (say frequency), that I want to map it back to the word.   orders by key, not value. Some resort to a , but is there a cleaner way?
2292
I have been working with a string[] array in C# that gets returned from a function call. I could possibly cast to a Generic collection, but I was wondering if there was a better way to do it, possibly by using a temp array.  What is the best way to remove duplicates from a C# array?
832
.NET offers a generic list container whose performance is almost identical (see Performance of Arrays vs. Lists question). However they are quite different in initialization.   Arrays are very easy to initialize with a default value, and by definition they already have certain size:  string[] Ar = new string[10];   Which allows one to safely assign random items, say:  Ar[5]="hello";   with list things are more tricky. I can see two ways of doing the same initialization, neither of which is what you would call elegant:  List&lt;string&gt; L = new List&lt;string&gt;(10); for (int i=0;i&lt;10;i++) L.Add(null);   or  string[] Ar = new string[10]; List&lt;string&gt; L = new List&lt;string&gt;(Ar);   What would be a cleaner way?  EDIT: The answers so far refer to capacity, which is something else than pre-populating a list. For example, on a list just created with a capacity of 10, one cannot do L[2]="somevalue"  EDIT 2: People wonder why I want to use lists this way, as it is not the way they are intended to be used. I can see two reasons:   One could quite convincingly argue that lists are the "next generation" arrays, adding flexibility with almost no penalty. Therefore one should use them by default. I'm pointing out they might not be as easy to initialize. What I'm currently writing is a base class offering default functionality as part of a bigger framework. In the default functionality I offer, the size of the List is known in advanced and therefore I could have used an array. However, I want to offer any base class the chance to dynamically extend it and therefore I opt for a list.
45310
Is there a built in function in .NET 2.0 that will take two arrays and merge them into one array?  The arrays are both of the same type. I'm getting these arrays from a widely used function within my code base and can't modify the function to return the data in a different format.  I'm looking to avoid writing my own function to accomplish this if possible.
80273
If I have a dictionary like:  { 'a': 1, 'b': 2, 'c': 3 }   How can I convert it to this?  [ ('a', 1), ('b', 2), ('c', 3) ]   And how can I convert it to this?  [ (1, 'a'), (2, 'b'), (3, 'c') ]
26601
Is there a Java equivalent for  in C#/.NET? Or any code to accomplish this?  This static method combines one or more strings into a path.
111486
So if I have to choose between a hash table or a prefix tree what are the discriminating factors that would lead me to choose one over the other. From my own naive point of view it seems as though using a trie has some extra overhead since it isn't stored as an array but that in terms of run time (assuming the longest key is the longest english word) it can be essentially O(1) (in relation to the upper bound). Maybe the longest english word is 50 characters?  Hash tables are instant look up once you get the index. Hashing the key to get the index however seems like it could easily take near 50 steps.  Can someone provide me a more experienced perspective on this? Thanks!
80355
I have this struct:  struct Map {     public int Size;      public Map ( int size )     {         this.Size = size;     }      public override string ToString ( )     {         return String.Format ( "Size: {0}", this.Size );     } }   When using array, it works:  Map [ ] arr = new Map [ 4 ] {     new Map(10),     new Map(20),     new Map(30),     new Map(40)};  arr [ 2 ].Size = 0;   But when using List, it doesn't compile:  List&lt;Map&gt; list = new List&lt;Map&gt; ( ) {     new Map(10),     new Map(20),     new Map(30),     new Map(40)};  list [ 2 ].Size = 0;   Why?
83564
I know VB.Net and am trying to brush up on my C#.  Is there a With block equivalent in C#?  Thanks
14108
Basically, I'm trying to create an object of unique objects, a set. I had the brilliant idea of just using a JavaScript object with objects for the property names. Such as,  set[obj] = true;   This works, up to a point. It works great with string and numbers, but with other objects, they all seem to "hash" to the same value and access the same property. Is there some kind of way I can generate a unique hash value for an object? How do strings and numbers do it, can I override the same behavior?
112859
Is there a better way to do this?  string[] s = {"zero", "one", "two", "three", "four", "five"};  var x =  s .Select((a,i) =&gt; new {Value = a, Index = i}) .Where(b =&gt; b.Value.StartsWith("t")) .Select(c =&gt; c.Index);   i.e. I'm looking for a more efficient or more elegant way to get the positions of the items matching the criteria.
6482
I've got a generic dictionary Dictionary&lt;string, T&gt; that I would like to essentially make a Clone() of ..any suggestions.
115478
I am using C#, Entity Framework. SQL Server for the development. I have a method which has two parameters (int ID, List&lt;String&gt; _listobj). For each ID, there is a list of obj. All of these IDs and lists will be inserted into different tables in database. So the question is: what's the best practice for this? I have couple of options:    In C#, split the list&lt;obj&gt; as single value, then create a stored procedure which takes two parameters (ID, str), then the C# will call the stored procedure many times depending on the size of the list Pass the ID and list&lt;obj&gt; as two parameters to the stored procedure and let the stored procedure split the list&lt;obj&gt;. This way C# will only call the stored procedure once   Is the second strategy doable? If yes, which is better in terms of performance?