Beispiel #1
0
    static void Main(string[] args)
    {
        var childClass1 = new ChildClass1();
        var childClass2 = new ChildClass2();

        childClass1.IncrementCounter();
        childClass2.ConsoleLogCounter();
    }
Beispiel #2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        ChildClass1 childClass1 = new ChildClass1();
        ChildClass2 childClass2 = new ChildClass2();
        ChildClass1 childClass3 = new ChildClass1();
        ChildClass2 childClass4 = new ChildClass2();
        ParentClass parentClass = new ParentClass();

        Response.Write("ChildClass count is:" + ParentClass.count);
    }
    static void Main(string[] args)
    {
        var a = new ChildClass1();
        var b = new ChildClass1();
        var c = new ChildClass2();

        a.Sample = 10;

        Console.WriteLine(a.Sample);         // 10
        Console.WriteLine(b.Sample);         // 10
        Console.WriteLine(c.Sample);         // 0
    }
        public static void MainMethod()
        {
            ChildClass child = new ChildClass();

            child.print();

            ChildClass2 child2 = new ChildClass2();

            child2.print();
            ((ParentClass2)child2).print();

            Casting();
        }
        public void TypeChecker(bool derivedTypes)
        {
            // Arrange
            var matchObject      = new ChildClass1();
            var noMatch          = new ChildClass2();
            var sameTypeCheck    = ReflectionTool.TypePredicate(typeof(ChildClass1), derivedTypes);
            var derivedTypeCheck = ReflectionTool.TypePredicate(typeof(BaseClass), derivedTypes);

            // Act
            var isSame    = sameTypeCheck(matchObject);
            var different = sameTypeCheck(noMatch);
            var isDerived = derivedTypeCheck(matchObject);

            // Assert
            Assert.IsTrue(isSame, "Comparison for the same type must always return true");
            Assert.IsFalse(different, "Comparison for incompatible types must return false");
            Assert.AreEqual(derivedTypes, isDerived, "Comparison for derived types should only work if configured that way");
        }
Beispiel #6
0
        public void ShowNewOrVitual()
        {
            BaseClass a = new BaseClass();
            BaseClass b = new ChildClass1();
            BaseClass c = new ChildClass2();
            ChildClass1 d = new ChildClass1();
            ChildClass1 e = new ChildClass2();
            ChildClass2 f = new ChildClass2();

            string all = string.Format("{0}\n{1}\n{2}\n{3}\n{4}\n{5}\n", a.Show(), b.Show(), c.Show(), d.Show(), e.Show(), f.Show());
        }