1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
| namespace TestDic
{
using System;
using System.Collections.Generic;
internal class Program
{
private static void Main()
{
Skill skill1 = new Skill {Name = "Skill Test", Num = 1};
Skill skill2 = new Skill {Name = "Skill Test", Num = 2};
Dictionary<string, Skill> dic = new Dictionary<string, Skill>(2);
dic.Add(skill1.ToString(), skill1);
Console.WriteLine("Lecture 1");
foreach(KeyValuePair<string, Skill> pair in dic)
{
Console.WriteLine("Key:{0} Skill:{1}", pair.Key, pair.Value);
}
Console.WriteLine("\nAjout du skill 2");
dic.Add(skill2.ToString(), skill2);
Console.WriteLine("\nLecture 2");
foreach(KeyValuePair<string, Skill> pair in dic)
{
Console.WriteLine("Key:{0} Skill:{1}", pair.Key, pair.Value);
}
skill2.Num = 3;
Console.WriteLine("\nNum du skill 2 vaut maintenant: {0}", skill2.Num);
Console.WriteLine("\nLecture 3");
foreach(KeyValuePair<string, Skill> pair in dic)
{
Console.WriteLine("Key:{0} Skill:{1}", pair.Key, pair.Value);
}
Console.Read();
}
#region Nested type: Skill
private class Skill
{
public String Name { get; set; }
public int Num { get; set; }
public override string ToString()
{
return string.Format("[{0}]+[{1}]", Name, Num);
}
}
#endregion
}
} |
Partager