operator

/*
 * 由SharpDevelop创建。
 * 用户: jinweijie
 * 日期: 2015/10/28
 * 时间: 9:15
 * 
 * 要改变这种模板请点击 工具|选项|代码编写|编辑标准头文件
 */
using System;

namespace Study
{
    class Fraction
    {
        int first;
        int second;
        public Fraction()
        {
        }
        public Fraction(int first,int second)
        {
            this.first = first;
            this.second = second;
        }
        public static Fraction operator +(Fraction lhs,Fraction rhs)
        {
            Fraction f = new Fraction();
            f.first = lhs.first + rhs.first;
            f.second = lhs.second + rhs.second;
            return f;
        }
        public void Display()
        {
            Console.WriteLine("first={0}  second={1}",first,second);
        }
    }
    class Program
    {
        public static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            
            // TODO: Implement Functionality Here
            Fraction  f1 = new Fraction(1,2);
            Fraction f2 = new Fraction(3,4);
            Fraction f3 = f1 + f2;
            f3.Display();
            
            
            Console.Write("Press any key to continue . . . ");
            Console.ReadKey(true);
        }
    }
}

上一篇:python中的双冒号作用


下一篇:hdu 5876 ACM/ICPC Dalian Online 1009 Sparse Graph