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);
        }
    }
}

 

上一篇:Shell入门


下一篇:Sqlite框架Delphi10.3