public override void method1()
    {
        MyDerived md = new MyDerived();

        //This is actually the base.base class implementation
        MyDerived.method1();
    }
Пример #2
0
        public No24_NotCreateGenericMethodSpecializeInBaseClassOrInterface()
        {
            //目的:
            //①利用者が混乱する挙動を避ける

            //概要:
            //--------------------------------------------------------------------------------------
            //ジェネリクスメソッドを先に公開し、それに特定の親クラスやインタフェースに特化した処理をさせたいという目的で
            //もとのジェネリクスメソッドをオーバーロードする形でメソッドを実装してはならない
            //コンパイラはジェネリクスメソッドを優先して採用するため、意識して親クラスやインタフェースにパースしないと
            //オーバーロードメソッドを使用することができない。これは利用者に対して混乱を招く
            //どうしてもやりたいなら、親クラス・インタフェース・継承するクラス・実装するクラス全てに対してオーバーロードメソッドを用意する
            //そうすれば厳密に型一致するのでオーバーロードメソッドを利用できる

            //実際の振る舞い
            var d = new MyDerived();
            var a = new AnotherType();

            //②が実行される
            GenericsAndOverLoad.WriteMessage(d);
            GenericsAndOverLoad.WriteMessage(a);
            //③が実行される
            GenericsAndOverLoad.WriteMessage((IMessageWriter)d);
            GenericsAndOverLoad.WriteMessage((IMessageWriter)a);
            //①が実行される
            GenericsAndOverLoad.WriteMessage((MyBase)d);

            //厳密な型一致が優先され、ジェネリクスメソッドが優先される
        }
Пример #3
0
    public static int Main()
    {
        I I1 = new MyDerived();

        System.Console.WriteLine("I1.Print<object>: " + I1.Print <object>());

        return(100);
    }
Пример #4
0
    public static int Main()
    {
        I I1 = new MyDerived();

        System.Console.WriteLine("I1.Print<object>: " + I1.Print<object>());

        return 100;
    }
Пример #5
0
    public void SuperCall5()
    {
        MyDerived a = NSObject.AllocAndInitInstance("MyDerived").To <MyDerived>();

        int result = a.SuperCall(new Class("MyBase"), "accumulate:", 1).To <int>();

        Assert.AreEqual(2, result);
    }
Пример #6
0
    public static void Main()
    {
        MyDerived mD = new MyDerived();
        MyBase    mB = (MyBase)mD;

        System.Console.WriteLine(mB.Meth1());
        System.Console.WriteLine(mB.Meth2());
        System.Console.WriteLine(mB.Meth3());
    }
    public static void Main()
    {
        var derived = new MyDerived();

        Console.WriteLine("Value = {0}", derived.GetValue());
        MyBase myBase = derived;

        Console.WriteLine("Value = {0}", myBase.GetValue());
    }
Пример #8
0
    public static void Main()
    {
        MyDerived mD = new MyDerived();
        MyBase mB = (MyBase)mD;

        System.Console.WriteLine(mB.Meth1());
        System.Console.WriteLine(mB.Meth2());
        System.Console.WriteLine(mB.Meth3());
    }
Пример #9
0
        static void Main(string[] args)
        {
            ////MyBaseC mB = new MyBaseC(); - Cannot Create an instance of the base Class.
            MyDerived myDerived = new MyDerived();

            myDerived.MyMethod();

            Console.WriteLine("x = {0}, y = {1}", myDerived.GetX, myDerived.GetY);
            Console.ReadLine();
        }
Пример #10
0
    public static void Main()
    {
        MyDerived myDerived = new MyDerived();

        Console.WriteLine();

        myDerived.Foo();
        Console.WriteLine();

        ((ITest)myDerived).Foo();
    }
Пример #11
0
        public static void Main()
        {
            MyDerived item = new MyDerived();
            Boolean   isIt = typeof(MyGeneric <>).BaseType.IsAssignableFrom(item.GetType());

            Console.WriteLine(isIt); // Output: "True"
            foreach (Type type in item.GetType().BaseType.GetGenericArguments())
            {
                Console.WriteLine(type.Name);
            }
        }
        public void TestMethod1()
        {
            MyClass ms = new MyClass(2);

            ms._asd = 10;
            Console.WriteLine(ms._asd);

            MyDerived md = new MyDerived(2f);

            Console.WriteLine(md._asd);
        }
Пример #13
0
    public void DeallocTest2()
    {
        NSObject pool = new NSObject(NSObject.AllocAndInitInstance("NSAutoreleasePool"));

        MyDerived instance = (MyDerived) new Class("MyDerived").Call("alloc").Call("init");

        Assert.AreEqual(1L, instance.retainCount());
        instance.release();
        Assert.IsTrue(instance.Dead);

        pool.release();
    }
Пример #14
0
    public static void Main()
    {
        MyDerived nMD = new MyDerived();
        Mybase    nMB = (Mybase)nMD;

        System.Console.WriteLine(nMB.Meth1());
        System.Console.WriteLine(nMB.Meth2());
        System.Console.WriteLine(nMB.Meth3());

        System.Console.WriteLine(nMD.Meth1());
        System.Console.WriteLine(nMD.Meth2());
        System.Console.WriteLine(nMD.Meth3());
    }
Пример #15
0
            public static void OverideDemo()
            {
                MyDerived mD = new MyDerived();
                MyBase    mB = (MyBase)mD;

                //overide重写后转回 还是重写后的继承方法。
                System.Console.WriteLine(mB.Meth1());

                // 使用 new 关键字显式隐藏
                System.Console.WriteLine(mB.Meth2());

                // 该方法隐藏了继承的成员 MyBase.Meth3():
                System.Console.WriteLine(mB.Meth3());
            }
Пример #16
0
    public void SuperCall2()
    {
        try
        {
            MyDerived b = NSObject.AllocAndInitInstance("MyDerived").To <MyDerived>();

            int result = b.accumulate(0);
            Assert.AreEqual(5, result);
        }
        catch (Exception e)
        {
            Console.WriteLine("SuperCall2 failed:");
            Console.WriteLine("{0}", e);
        }
    }
        static void PolymorphismConcepts()
        {
            MyHelper.PrintHeaderMessage("Base Reference Base Object");
            MyBase obj1 = new MyBase(); obj1.f1(); obj1.f2(); obj1.f3(); obj1.f4(); obj1.f5();

            MyHelper.PrintNoteConcept("In this case, all base function will be called.");

            MyHelper.PrintHeaderMessage("Derived Reference Derived Object");
            MyDerived obj2 = new MyDerived(); obj2.f1(); obj2.f2(); obj2.f3(); obj2.f4(); obj2.f5();

            MyHelper.PrintNoteConcept("In this case, all derived function will be called.");

            MyHelper.PrintHeaderMessage("Base Reference Derived Object");
            MyBase obj3 = new MyDerived(); obj3.f1(); obj3.f2(); obj3.f3(); obj3.f4(); obj3.f5();

            MyHelper.PrintNoteConcept("In this case, Only derived override will be called else all base will be called");

            Console.Out.WriteLine("Derived Reference  Base Object With Type Cast");
            //MyDerived obj4 = (MyDerived)new MyBase(); obj4.f1(); obj4.f2(); obj4.f3(); obj4.f4(); obj4.f5();
            MyHelper.PrintNoteConcept("Run Time Error: Unable to cast Base type to Derived type");

            MyHelper.PrintNoteConcept();
            MyHelper.PrintEndMessage();
        }
Пример #18
0
	        public static bool testMethod() {	
		        MethodsTestClass59 test = new MethodsTestClass59();
		        MyDerived md = new MyDerived();
		        if (test.TestMeth(md) == 2) {
			        return true;
		        }
		        else {
			        return false;
		        }
	        }
Пример #19
0
    public static void Main()
    {
        Employee E = new Employee();
        E.GetInfo();

        MyDerived md = new MyDerived();
        MyDerived md1 = new MyDerived(1);

        Console.ReadLine();
    }
Пример #20
0
    public static void Main()
    {
        var o = new MyDerived();

        o.HelloWorld();
    }
Пример #21
0
 public NSObject TakeDerived(MyDerived s)
 {
     return (NSObject) s.Call("description");
 }
Пример #22
0
 public NSObject TakeDerived(MyDerived s)
 {
     return((NSObject)s.Call("description"));
 }
Пример #23
0
 protected virtual FooBase Overloaded(MyDerived myBase)
 {
     return(null);
 }
 public void SetAsList2(bool flag, MyDerived[] a, IList<MyClass> b, out IList<MyClass> result)
 {
     result = flag ? a : b;
 }
        public static void Main(string[] args)
        {
            MyDerived obj = new MyDerived();

            obj.Method <int, int> (1);
        }
Пример #26
0
        static void Main(string[] args)
        {
            //IcertisDemo.VersionFilters versionFilters = new IcertisDemo.VersionFilters();
            //versionFilters.Message = "Hello December!!!";
            //versionFilters.PrintMessage(versionFilters.Message);

            MyDerived myDerived = new MyDerived();


            //CrediCardAccounts ccAcc = new CrediCardAccounts();
            //string car = "Maruti";
            //Car maruti = null;
            //Vehicle.Print(maruti);
            //ActionTypeDemo.GetPerson();

            //OOPsDemo.GetFamilyMember();

            //using (var oops = new OOPsDemo()) {
            //    oops.WriteTrasaction();
            //    Console.WriteLine("Using Statement");
            //}

            //VersionFilters versionFilters = new VersionFilters();
            //versionFilters.GetOldestVersion();

            //string city = "Pune";
            //static string country = "India";
            //const string state = "MH";

            //Console.WriteLine(string.Format("You are in {0} {1} {2}", city, state, country));

            //SimplifyHealthCareTest simplifyTest = new SimplifyHealthCareTest();
            //int[] marks = new int[] { 4, 9, 4, 3, 2, 10 };
            //simplifyTest.GetSelctionChances(20, new int[] { 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 });

            //CitiBank citiBank = new CitiBank();
            //IA aRef = new CitiBank();
            //IB bRef = new CitiBank();
            //aRef.Show("IA interface calling.");
            //bRef.Show("IB interface calling.");
            //citiBank.Show("citi bank interview");
            //NiceParent child = new NiceChild();
            //child.Print();

            // AccessModifier_Derived accessModifier_Derived = new AccessModifier_Derived();
            //accessModifier_Derived.Print2();

            //AccessModifier_Derived2 accessModifier_Derived2 = new AccessModifier_Derived2();
            //accessModifier_Derived2.Print();

            // Maths2 t = new Maths2(10);
            Console.WriteLine("Enter the number...");
            int n = Convert.ToInt32(Console.ReadLine().Trim());

            AmazonTest.fizzBuzz(n);
            Console.WriteLine("Do you want to run again, press Y...");
            string choice = Console.ReadLine().Trim();

            IsRunAgain(choice);
            Console.ReadLine();
        }
Пример #27
0
 public void Run()
 {
     MyDerived d = new MyDerived();
     ((MyInterface)d).Test();
 }