Blog Home  Home Feed your aggregator (RSS 2.0)  
artiso Blog - Neue Add-Methode bei Dictionaries
Neues rund um's Thema .Net
 
 Wednesday, October 17, 2007

Preisfrage: Was passiert bei folgendem Code:

Dictionary<int, string> Names = new Dictionary<int, string> { { 1, "Thomas" }, { 2, "Chris" } };
Names[5] = "Luka";


Ich hätte erwartet, dass der eine KeyNotFoundException wirft. Tut er aber nicht. Statt dessen wird einfach ein neues Element dem Dictionary hinzugefügt mit dem Key 5 und dem Value "Luka". Ob man das verwenden sollte sei mal dahingestellt, aber zumindest gut zu wissen.

Wednesday, October 17, 2007 5:13:36 PM (Mitteleuropäische Zeit, UTC+01:00)  #    Comments [0]    | 
Copyright © 2008 Thomas. All rights reserved.
DasBlog 'Portal' theme by Johnny Hughes.
Pick a theme: