看这个简单的例子吧,直接用类的实例调用就可以了~~~
public class person
{
private string name;
privaet int age;
public person(string thename,int theage)
{
name = thename;
age = theage;
}
public string Name
{
get{return name;}
set{name = value;}
}
public static bool operator > (person p1,person p2) //运算符的重载
{
if(p1.age > p2.age)
{
return true;
}
else
return false;
}
public static bool operator < (person p1,person p2) //配套运算符必须同时重载
{
return !(p1 > p2)
}
}
...
...
person a = new person("Jude",20);
person b = new person("Law",30);
if(a > b)
{
console.writeline("{0} is older than {1}",a.Name,b.Name);
}
if(a < b)
{
console.writeline("{0} is younger than {1}",a.Name,b.Name);
}
你是我心内的一首歌,不要只是个过客;在我生命留下一首歌,无论结局会如何.