1 public interface IA { }
2 public class A1 : IA { }
3 public class A2 : IA { }
4
5 public static class AContainer
6 {
7 private static readonly Dictionary<string, IA> Items = new Dictionary<string, IA>();
8 public static Dictionary<string, IA> As{ get { return Items; } }
9 }
1 class Program
2 {
3 static void Main()
4 {
5 Console.WriteLine(AContainer.As.Count);
6 AContainer.As.Add("A1", new A1());
7 Console.WriteLine(AContainer.As.Count);
8 AContainer.As.Add("A2", new A2());
9 Console.WriteLine(AContainer.As.Count);
10 // we can remove all the item of the collection
11 AContainer.As.Clear();
12 Console.WriteLine(AContainer.As.Count);
13 Console.ReadKey();
14 }
15
16 }
1 using System;
2 using System.Reflection;
3
4 namespace SOVT
5 {
6 public class Foo
7 {
8 private readonly int bar;
9 public Foo(int num) { bar = num; }
10 public int GetBar() { return bar; }
11 }
12
13 class Program
14 {
15 static void Main()
16 {
17 Foo foo = new Foo(123);
18 Console.WriteLine(foo.GetBar());
19 FieldInfo fieldInfo = typeof(Foo).GetField("bar", BindingFlags.Instance | BindingFlags.NonPublic);
20 if (fieldInfo != null)
21 fieldInfo.SetValue(foo, 567);
22 Console.WriteLine(foo.GetBar());
23 Console.ReadKey();
24 }
25 }
26 }