Re: Dictionary class lacks the very basic function ?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



I want to use Dictionary class like this:

textboxM.Text = oMyDict.GetValue("textboxM");
textboxN.Text = oMyDict.GetValue("textboxN");

Where my dictionary contains the list of values for my textbox based on
the textbox id.

But it doesn't have it !

Use the indexer

textboxM.Text = oMyDict["textboxM"];


TryGetValue !? What's that ? Why I have to provide an out parameter,
isn't more simple just return the value or null if not found !?

A Dictionary can be instantiated with a value type that isn't
nullable, so returning null isn't always an option. That's why
TryGetValue is needed.


Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
.



Relevant Pages

  • Re: .net 2005 convert from VB to c++
    ... Private Sub textbox1_KeyPress(ByVal sender As Object, ... This code doesn't handle strings that gets pasted into the textbox. ... plain Windows APIs? ... Mattias Sjögren mattias @ mvps.org ...
    (microsoft.public.dotnet.general)
  • Re: Type.GetType returns null for Systems.Windows.Forms.TextBox
    ... Because you didn't specify which assembly it should look in. ... if (yourControl is TextBox) ... ... Mattias Sjögren mattias @ mvps.org ... Please reply only to the newsgroup. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: User Form to Word Doc
    ... This message is posted to a newsgroup. ... >>> same ID names as the USerForm ones. ... >>> Private Sub QuoteNo_Change ... >>> {this is for the textbox in the user form} ...
    (microsoft.public.word.vba.userforms)
  • Re: Admin abuse on this news group...
    ... With wordWrap and the Width of the textBox gives me ... There is obviously something with this newsgroup. ... I find it bolt from you to tell direct that Peter did that, ... answered correctly by pvdg42. ...
    (microsoft.public.dotnet.general)
  • =?ISO-8859-1?Q?Re:Bildschirm_positzionieren,_Aktives_Textbox_Zeigen?=
    ... der jeweiligen Textbox gelegene) Zelle zu selektieren, ... Private Sub TextBox2_GotFocus ... Jose Manuel schrieb in der newsgroup microsoft.public.de.excel: ... Next by Date: ...
    (microsoft.public.de.excel)