编程语言
首页 > 编程语言> > C#操作符重载

C#操作符重载

作者:互联网

namespace 操作符重载
{
    internal class Program
    {
        static void Main(string[] args)
        {
            var a = new Test(11);

            var b = new Test(12);

            var c = a + b;

            Console.WriteLine(c.Lenght);

            Console.ReadKey();
        }
    }

    internal class Test
    {
        public Test(int length)
        {
            Lenght = length;
        }

        public int Lenght { get; set; }

        public static Test operator +(Test test1, Test test2)
        {
            return new Test(test1.Lenght + test2.Lenght);
        }
    }
}

 

标签:test1,C#,Lenght,var,Test,操作符,重载,new,public
来源: https://www.cnblogs.com/niaofei123/p/15675632.html