Questions tagged [idictionary]

System.Collections.IDictionary and System.Collections.Generic.IDictionary interfaces in the BCL (Base Class Library) of the .NET framework represent a collection of key-value pairs.

System.Collections.IDictionary and System.Collections.Generic.IDictionary<TKey, TValue>interfaces in the BCL (Base Class Library) of the .NET framework represent a collection of key-value pairs.

MSDN links:

148 questions
217
votes
2 answers

Recreating a Dictionary from an IEnumerable>

I have a method that returns an IEnumerable>, but some of the callers require the result of the method to be a dictionary. How can I convert the IEnumerable> into a Dictionary
learnerplates
  • 4,257
  • 5
  • 33
  • 42
56
votes
4 answers

Convert List of KeyValuePair into IDictionary "C#"

My scenario, how to convert List> into IDictionary?
anbuselvan
  • 1,201
  • 4
  • 16
  • 21
28
votes
1 answer

Why doesn't the C# Dictionary implement all of IDictionary?

I wanted to create a Dictionary-like object and thought the correct way would be to implement the IDictionary interface, and use composition to include the underlying dictionary. I began with the below (K=string, V=int) public class…
Marc Meketon
  • 2,463
  • 1
  • 24
  • 21
25
votes
2 answers

Dictionary.ContainsKey() - How does it work?

I've read the MSDN documentation on how Dictionary.ContainsKey() works, but I was wondering how it actually makes the equality comparison? Basically, I have a dictionary keyed to a reference type* and I want the ContainsKey() method to check a…
Richard
  • 991
  • 2
  • 11
  • 24
23
votes
4 answers

Create a Dictionary in xaml?

Pseudo example:
Shimmy Weitzhandler
  • 101,809
  • 122
  • 424
  • 632
21
votes
2 answers

How to iterate through keys and values of an `IDictionary`?

How would I iterate through the keys and values of an IDictionary if I don't know the concrete types of the keys and values within, therefore want to just treat them as objects? If I do something like: foreach(var x in myIDictionary) { ... } I think…
Joseph Humfrey
  • 2,974
  • 2
  • 23
  • 34
20
votes
5 answers

How to initialize a ConcurrentDictionary? Error: "Cannot access private method 'Add' here"

I have a static class in which I am using dictionaries as lookup tables to map between .NET types and SQL types. Here is an example of such a dictionary: private static readonly Dictionary SqlServerMap = new Dictionary { …
Drew
  • 1,277
  • 3
  • 21
  • 39
19
votes
2 answers

Why does Dictionary.ContainsKey throw ArgumentNullException?

The documentation states that bool Dictionary.ContainsKey(TKey key) throws an exception in case a null key is passed. Could anyone give a reason for that? Wouldn't it be more practical if it just returned false?
Marcin Kaczmarek
  • 1,063
  • 2
  • 9
  • 20
19
votes
8 answers

Need an IDictionary implementation that will allow a null key

Basically, I want something like this: Dictionary dict = new Dictionary(); dict.Add(null, "Nothing"); dict.Add(1, "One"); Are there any built into the base class library that allow this? The preceding code will…
Clyde
  • 8,017
  • 11
  • 56
  • 87
13
votes
3 answers

Extension methods for both IDictionary and IReadOnlyDictionary

My question is similar to the previous one, but the answer to that question is inapplicable to this one. Well, I want to write an extension method for both IDictionary and IReadOnlyDictionary interfaces: public static TValue? GetNullable
user1067514
  • 494
  • 3
  • 15
12
votes
7 answers

Is there a limit to entries in a Dictionary<>?

I have about 3000 different files I need to organize, and retrieve at different times during the game. I created my own struct of variables. I was thinking about creating a "Dictionary " at the beginning of my application, and simply loading all my…
theoneawaited
  • 123
  • 1
  • 1
  • 5
11
votes
2 answers

Getting values of a generic IDictionary using reflection

I have an instance that implements IDictionary, I don't know T and K at compiletime, and want to get all elements from it. I don't want to use IEnumerable for some reason, which would be the only non-generic interface implemented by…
Stefan Steinegger
  • 63,782
  • 15
  • 129
  • 193
11
votes
1 answer

Can't view Dictionary contents in Visual Studio debugger

I have a System.Collections.Generic.Dictionary object in my code and am trying to view its contents while stopped at a breakpoint in the Visual Studio debugger. The Dictionary class in .NET of course contains a list of keys and values. If I…
Buggieboy
  • 4,636
  • 4
  • 55
  • 79
10
votes
3 answers

When SortedDictionary is enumerated does it return KeyValuePairs in expected order?

When I have SortedDictionary in .NET and I want to enumerate it as ICollection> does it enumerate in expected order? That is KeyValuePair with lowest key is returned as first, folloved by KeyValuePair
Rasto
  • 17,204
  • 47
  • 154
  • 245
10
votes
7 answers

c# Dictionary how to loop through items without knowing key

I have a: var selectedDates = new Dictionary(); selectedDates.Add("2014-06-21", DateTime.Now.ToLongDateString()); selectedDates.Add("2014-07-21", DateTime.Now.AddDays(5).ToLongDateString()); selectedDates.Add("2014-08-21",…
VAAA
  • 14,531
  • 28
  • 130
  • 253
1
2 3
9 10