重载的问题
using System;using System.Collections.Generic;
using System.Text;
namespace _80714chongzai
{
class Program
{
public class Complex
{
public int real;
public int imaginary;
public Complex(int real , int imaginary)
{
this.real = real;
this.imaginary = imaginary;
}
public static Complex operator +(Complex x1,Complex x2)
{
return new Complex(x1.real + x2.real, x1.imaginary + x2.imaginary);
}
public override string ToString()
{
return (String.Format("{0}+{1}i", real, imaginary));
}
static void Main(string[] args)
{
Complex num1 = new Complex(2, 3);
Complex num2 = new Complex(3, 4);
Complex sum = num1 + num2;
Console.WriteLine("1:\t{0}", num1);
Console.WriteLine("2:\t{0}", num2);
Console.WriteLine("1+2:\t{0}", num1 + num2);
}
}
}
}
这里public static Complex operator +(Complex x1,Complex x2)中的operator + 是什么用呢