C# this 关键字

class A
    {
        public int num = 3;
        public void m1(B b)
        {
            b.m2(this);
        }
    }
    class B
    {       
        public void m2(A a)
        {
            Console.WriteLine(a.num);
        }
    }
    
    class Test
    {
        public static void Main(string[] args)
        {
            A a = new A();
            B b = new B();
            a.m1(b);      //3
        }
    }  

 

posted @ 2022-11-07 19:58  竹楼风雨声  阅读(17)  评论(0编辑  收藏  举报