public class fuhao
{
private string thc;
private int age;
public fuhao()
{
//构造一个空的构造函数
}
public fuhao(string nthc, int nage)
{
thc = nthc;
age = nage;
}
public string Thc
{
get
{
return thc;
}
}
public int Age
{
get
{
return age;
}
}
public static bool operator ==(fuhao a, fuhao b)//重载"==",重载的参数是fuhao类的两个对象
{
if (a.Thc == b.Thc && a.Age == a.Age)
{
return true;
}
else
{
return false;
}
}
public static bool operator !=(fuhao a, fuhao b)//重载“!=”,返回的值是bool型的,重载的对象是fuhao类的两个对象
{
return !(a == b);
}
public static string operator +(fuhao a, fuhao b)//重载“+”,返回的类型是string,重载的对象是fuhao类的两个对象
{
return "<br>" + a.Thc + a.Age + "<br>" + b.Thc + b.Age + "岁";
}
}
protected void Page_Load(object sender, EventArgs e)
{
fuhao fh= new fuhao("klj",21);
fuhao fh1 = new fuhao("jhkj",21);
Response.Write(fh+fh1);//在这里怎么用operator这个方法,为什么可以这样用?
}谢了
{
private string thc;
private int age;
public fuhao()
{
//构造一个空的构造函数
}
public fuhao(string nthc, int nage)
{
thc = nthc;
age = nage;
}
public string Thc
{
get
{
return thc;
}
}
public int Age
{
get
{
return age;
}
}
public static bool operator ==(fuhao a, fuhao b)//重载"==",重载的参数是fuhao类的两个对象
{
if (a.Thc == b.Thc && a.Age == a.Age)
{
return true;
}
else
{
return false;
}
}
public static bool operator !=(fuhao a, fuhao b)//重载“!=”,返回的值是bool型的,重载的对象是fuhao类的两个对象
{
return !(a == b);
}
public static string operator +(fuhao a, fuhao b)//重载“+”,返回的类型是string,重载的对象是fuhao类的两个对象
{
return "<br>" + a.Thc + a.Age + "<br>" + b.Thc + b.Age + "岁";
}
}
protected void Page_Load(object sender, EventArgs e)
{
fuhao fh= new fuhao("klj",21);
fuhao fh1 = new fuhao("jhkj",21);
Response.Write(fh+fh1);//在这里怎么用operator这个方法,为什么可以这样用?
}谢了
解决方案 »
- [分享]把程序锁定到Win7任务栏
- winform 中点击"X"弹出提示是否关闭的问题...........
- winform.controls(0)就是一个Textbox,为什么不能直接winform.controls(0).text="value" ?
- VS2005 开发水晶报表的问题?请大家帮帮忙!
- 如何在C#中配置membership使用
- 如何使用windows API获取TTC字体文件信息
- 请教:C#如果读取Word文档中的内容,读取Word2003和Word2000方法是否相同
- 我们设计的逻辑层,用了很多类, 是否合理?
- WCF,请教一下双工
- DataGrid表中行的变色问题
- Vs 2005问题
- 用vpn将同一座城市的几台电脑连起来,当internet不通时是否会造成这几台电脑相互不能通信。隐藏,在采用VPN之前就应该考虑一旦internet不通时营业数据如何交互,因为internet并不能保证时时都畅通。如果真发生不通的情况,一般要怎么解决数据交
fh+fh1这两个类才能相加