static void Main() { MyClass2 ob1 = new MyClass2(4, 5); MyClass2 ob2 = new MyClass2(6, 7); Console.Write("ob1: "); ob1.Show(); Console.Write("ob2: "); ob2.Show(); if (ob1.SameAs(ob2)) { Console.WriteLine("ob1 and ob2 have the same values."); } else { Console.WriteLine("ob1 and ob2 have different values."); } Console.WriteLine(); // Now, make ob1 a copy of ob2. ob1.Copy(ob2); Console.Write("ob1 after copy: "); ob1.Show(); if (ob1.SameAs(ob2)) { Console.WriteLine("ob1 and ob2 have the same values."); } else { Console.WriteLine("ob1 and ob2 have different values."); } }
public static void Main() { MyClass2 <MyClass> mc2 = new MyClass2 <MyClass>(); mc2.SetXName(100, "abc"); mc2.Show(); }
public static void MainContrVar() { IMyContrVarGenIF <Alpha2> AlphaRef = new MyClass2 <Alpha2>(); IMyContrVarGenIF <Beta2> BetaRef = new MyClass2 <Beta2>(); IMyContrVarGenIF <Beta2> BetaRef2 = new MyClass2 <Alpha2>(); // контвариантность BetaRef.Show(new Beta2()); BetaRef = AlphaRef; // контвариантность BetaRef2.Show(new Beta2()); }