Csharp/CSharp Tutorial/Generic/Generic Dictionary

Материал из .Net Framework эксперт
Версия от 15:14, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

Create and use a generic Dictionary

<source lang="csharp">using System; using System.Reflection; using System.Collections.Generic;

class MainClass {

   public static void Main(string[] args)
   {
       Dictionary<string,MyClass> MyClassDictionary = new Dictionary<string,MyClass>();
       MyClassDictionary.Add("Crypto", new MyClass());
       MyClass myClass = MyClassDictionary["Crypto"];
       Console.WriteLine("Got from dictionary: {0}", myClass);
   }

} class MyClass {

  public override string ToString(){
   
     return "my class";
  }
   

}</source>

Got from dictionary: my class