What Was I Thinking?

Follies & Foils of .NET Development

  Home  |   Contact  |   Syndication    |   Login
  41 Posts | 0 Stories | 97 Comments | 0 Trackbacks

News

Archives

Post Categories

Check These Out

Gurus

Monday, October 19, 2009 #

When adding an item to a dictionary, I always thought you had to use the Add() method, like this:

string key = "MyKey";
int value = 20;
var myDictionary = new Dictionary<string, int>();
myDictionary.Add(key, value);

Apparently, you can directly reference it in the collection, and if the key doesn’t exist, its auto-added to the collection

string key = "MyKey";
int value = 20;
var myDictionary = new Dictionary<string, int>();
myDictionary[key] = value;

most likely you already knew this.  I did not.  Its the little things I guess.