//operator 符号重载时使用 相当于NEW 指定要重载哪个运算符
构造一个类
在Page_Load中使用
构造一个类
public class fuhao
{
private string mgod;
private int age;
public fuhao()
{
//构造一个空的函数
}
public fuhao(string nMgod,int Nage)
{
mgod=nMgod;
age=Nage;
}
public string Mgod
{
get
{
return mgod;
}
}
public string Age
{
get
{
return age;
}
}
public static bool operator==(fuhao a,fuhao b)
{
if(a.Mgod=b.Mgod&&a.Age==b.Age)
{
return true;
}
else
{
return false;
}
}
public static bool operator!=(fuhao a,fuhao b)
{
return !(a==b);
}
public static string operator +(fuhao a,fuhao b)
{
return "<br>"+a.Mgod+a.Age+"<br>"+b.Mgod+b.Age+"岁";
}
}
{
private string mgod;
private int age;
public fuhao()
{
//构造一个空的函数
}
public fuhao(string nMgod,int Nage)
{
mgod=nMgod;
age=Nage;
}
public string Mgod
{
get
{
return mgod;
}
}
public string Age
{
get
{
return age;
}
}
public static bool operator==(fuhao a,fuhao b)
{
if(a.Mgod=b.Mgod&&a.Age==b.Age)
{
return true;
}
else
{
return false;
}
}
public static bool operator!=(fuhao a,fuhao b)
{
return !(a==b);
}
public static string operator +(fuhao a,fuhao b)
{
return "<br>"+a.Mgod+a.Age+"<br>"+b.Mgod+b.Age+"岁";
}
}
在Page_Load中使用
fuhao fh=new fuhao("赤色火焰",21);
fuhao fh1=new fuhao("mgod",22);
Response.Write(fh==fh1);//返回false
Response.Write(fh!=fh1);//返回true
Response.Write(fh+fh1);//返回 赤色火焰21 mgod22岁
fuhao fh1=new fuhao("mgod",22);
Response.Write(fh==fh1);//返回false
Response.Write(fh!=fh1);//返回true
Response.Write(fh+fh1);//返回 赤色火焰21 mgod22岁