码迷,mamicode.com
首页 > 其他好文 > 详细

class struct Equals

时间:2017-04-19 09:24:16      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:write   turn   div   nbsp   set   main   class   string   private   

{
    class clsA
    {
        private int _i;
        public int I 
        {
            set { _i = value; }
            get { return _i; } 
        }
    }

    struct strctB
    {
        private int _i;
        public int I
        {
            set { _i = value; }
            get { return _i; }
        }
    }

    class Program
    {
        static void Main1(string[] args)
        {
            clsA a1=new clsA();
            a1.I=1;
            clsA a2=a1;
            a2.I=2;
            Console.WriteLine("{0},{1}", a1.I, a2.I);//2,2
            strctB b1=new strctB();
            b1.I = 1;
            strctB b2=b1;
            b2.I = 2;
            Console.WriteLine("{0},{1}", b1.I, b2.I);//1,2
        }
        static void Main(string[] args)
        {
            clsA a1 = new clsA();
            a1.I = 1;
            clsA a2 = new clsA();
            a2.I = 1;
            Console.WriteLine("{0}", a1.Equals(a2));//False
            strctB b1 = new strctB();
            b1.I = 1;
            strctB b2 = new strctB();
            b2.I = 1;
            Console.WriteLine("{0}", b1.Equals(b2));//True
        }
    }
}

 

class struct Equals

标签:write   turn   div   nbsp   set   main   class   string   private   

原文地址:http://www.cnblogs.com/sky20080101/p/6731603.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!