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
9
votes
2 answers

Remove all items that match a condition in IDictionary

I'm trying to remove all elements in a IDictionary object that match a condition. E.g. the IDictionary contains a set of keys and corresponding values (let say 80 objects). The keys are strings, the values could be of different types (think…
rboy
  • 2,018
  • 1
  • 23
  • 35
8
votes
1 answer

How to convert a list of dictionaries into IDictionary “C#”

There is this answer of a query I am trying to understand what to put into this LINQ segment pair => pair.Key, pair => pair.Value My exact List definition is this: List> myList = new List
heavy rocker dude
  • 2,271
  • 8
  • 33
  • 47
8
votes
7 answers

Convert IDictionary keys to lowercase (C#)

I've got a Method that gets a IDictionary as a parameter. Now I want to provide a method that retrieves the value from this dictionary, but it should be case-invariant. So my solution to this right now was to have a static function that loops…
Tigraine
  • 23,358
  • 11
  • 65
  • 110
7
votes
4 answers

Is there a better data structure than Dictionary if the values are objects and a property of those objects are the keys?

I have a Dictionary where the int is a property of obj. Is there a better data structure for this? I feel like using a property as the key is redundant. This Dictionary is a field in a container class that allows for random…
Brian Triplett
  • 3,462
  • 6
  • 35
  • 61
7
votes
1 answer

System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary

I receive the above error message when performing a unit test on a method. I know where the problem is at, I just don't know why it's not present in the dictionary. Here is the dictionary: var nmDict = xelem.Descendants(plantNS +…
Programming Newbie
  • 1,207
  • 5
  • 31
  • 51
6
votes
2 answers

Code Contracts: Ensures Unproven & Requires Unproven

I'm not sure if I'm doing something wrong here or if it needs to be fixed... I have a custom Dictionary wrapper class and here is a snippet of the code that is necessary. public int Count { get { …
michael
  • 14,844
  • 28
  • 89
  • 177
6
votes
2 answers

IDictionary How to get the removed item value while removing

I would like to know if it is possible to remove an IDictionary item by its key and in the same time get its actual value that has been removed? Example something like: Dictionary myDic = new Dictionary(); myDic["key1"]…
Shahar Shokrani
  • 7,598
  • 9
  • 48
  • 91
6
votes
2 answers

Why does not IDictionary (non-generic) inherit from IEnumerable?

IDictionary inherits from IEnumerable>, but IDictionary for some reason doesn't inherit from IEnumerable. I wonder why? I hate to write this ugly .OfType() every time when I…
thorn0
  • 9,362
  • 3
  • 68
  • 96
5
votes
3 answers

How do I alter the contents of IDictionary using LINQ (C# 3.0)

How do I alter the contents of an IDictionary using C# 3.0 (Linq, Linq extensions) ? var enumerable = new int [] { 1, 2}; var dictionary = enumerable.ToDictionary(a=>a,a=>0); //some code //now I want to change all values to 1 without recreating the…
Jader Dias
  • 88,211
  • 155
  • 421
  • 625
5
votes
5 answers

Purpose of IDictionary interface

What is the need of IDictionary interface. How can IDictionary interface be initialized. After all it is just an interface. The following code snippet is from msdn. I could not understand it. IDictionary openWith = new…
softwarematter
  • 28,015
  • 64
  • 169
  • 263
5
votes
3 answers

Difference between anonymous class and IDictionary for htmlAttributes in ASP.NET MVC?

For example if you check these two extension methods the only difference is type of htmlAttributes so you can pass your htmlAttributes in two different ways: public static MvcHtmlString TextBoxFor( this HtmlHelper
Azadeh Khojandi
  • 3,806
  • 1
  • 30
  • 32
5
votes
3 answers

Dictionary> to IDictionary>?

Please consider the following code: class Student { } enum StudentType { } static void foo(IDictionary> students) { } static void Main(string[] args) { Dictionary> studentDict = …
5
votes
4 answers

Cast all keys in dictionary to uppercase

This is probably a very simple question but google has let me down sofar and keeps pointing me towards python solutions. I have a webpage where applciations/users can supply querystringparameters.To Retrieve the querystring parameters I use the…
User999999
  • 2,500
  • 7
  • 37
  • 63
5
votes
3 answers

Iterate over IDictionary with implicit DictionaryEntry

Consider this code: var variables = System.Environment.GetEnvironmentVariables(); foreach (DictionaryEntry vari in variables) { Console.WriteLine(vari.Key); Console.WriteLine(vari.Value); } It works fine. Since variables is IDictionary, it…
Piotr Zierhoffer
  • 5,005
  • 1
  • 38
  • 59
4
votes
2 answers

How to return all KeyValuePairs of a IDictionary C#

I want to write a method which return all key value pairs containing in a IDictionary as Map.EntrySet() does in java. I tried as: For example we define IDictionary as: private IDictionary _map = new Dictionary(); …
maliks
  • 1,102
  • 3
  • 18
  • 42
1
2
3
9 10