c# - Dictionary keyed on a property of the stored data -


What is the easiest way to create a dictionary that will be placed on the property of the data object? Like I think:

  interface A {string key {get;} // other stuff}  

I have so far:

  IDictionary & lt; String, A & gt; Dict = new dictionary & lt; String, A & gt; (); Add Zero (AA) {dict [a.Key] = a; // I would like that the collection class manages this relationship} Get one (string key) {return word [key]; }  

Is this a good way to achieve this? (IDictionary does not need to implement the archive, as long as it has the necessary index).

You can use:

  public class MyCollection: KeyedCollection & Lt; String, a & gt; {Safe Override GetKeyForItem (AA) {return a.Key; }}  

Comments