Dictionary with a single element
5 answers
You cannot get the value directly or by index, you either need to know the key:
object obj = yourDictionary[theKeyThatYouHappenToKnow];
or use a counter:
var en = yourDictionary.GetEnumerator();
en.MoveNext();
object obj = en.Current.Value;
en.Dispose();
If you are using the 3.5 framework you can also use an extension method like Single
or First
to use the counter for you.
+1
a source to share