Legen Sie Wert für DictionaryEntry

Bitte siehe mein code:

IDictionary dictionary = new Hashtable();
const string key = "key";
const string value = "value";
dictionary[key] = null; //set some trigger here

//set value
IDictionaryEnumerator dictionaryEnumerator = dictionary.GetEnumerator();
while (dictionaryEnumerator.MoveNext())
{
    DictionaryEntry entry = dictionaryEnumerator.Entry;
    if (entry.Value == null) //some business logic check; check for null value here
    {
        entry.Value = value; //set new value here
        break;
    }
}

Assert.AreEqual(value, dictionary[key]); //I have Fail here!

Frage ich mich :

  1. Was ist der richtige Ansatz für neue set-Wert für IDictionary, wenn
    Ich weiß nicht, die entsprechende Taste.
  2. Warum mein Beispiel nicht funktioniert? So wie ich das verstehe habe ich neue Wert
    für DictionaryEntry von Wert (und der Wert hier ist ein Verweis), aber
    es war nicht betroffen Quelle IDictionary. Warum?
gibt es einen Grund, Sie nicht verwenden ein generisches Wörterbuch? Dictionary<string,string>
ja, ich kann nicht mit Generika

InformationsquelleAutor Michael Z | 2012-03-27

Schreibe einen Kommentar