static void Main(string[] args)
 {
     var d = new SomeDerived
     {
         int_value = 10,
         str_value = "some string",
     };
 }
Beispiel #2
0
 public SomeObject(SomeDerived obj)
 {
     if (obj.obj == null)
     {
         // You have the reference to SomeDerived here
         // But its properties are not yet initialized (both SomeDerived and SomeBase constructors are in the progress of execution)
         // So you should not access them in the SomeObject class constructor
     }
 }
    static void Main()
    {
        var item1 = new SomeBase();
        var item2 = new SomeDerived();
        var items = new List <ISomeInterface> {
            item1, item2
        };
        ISomeInterface group = GroupGenerator.Create(items);

        group.SetSomeBool(true);
        Console.WriteLine(item1.SomeBool);     // true
        Console.WriteLine(item2.SomeBool);     // true
        group.SetSomeBool(false);
        Console.WriteLine(item1.SomeBool);     // false
        Console.WriteLine(item2.SomeBool);     // false
    }