C# 下面这些代码 出现错误Customerlnfo不实现接口,怎么回事?如果有时间,请讲解一下泛型的意思,谢谢
classCustomerlnfo:IComparable<Customerlnfo>{publicstringid{get;set;}publicstringname{...
class Customerlnfo:IComparable<Customerlnfo>
{
public string id{get;set;}
public string name{get;set;}
public string address{get;set;}
public Customerlnfo(string myid,string myname,string myaddress)
{
this.id=myid;
this.name=myname;
this.address=myname;
}
public int ASV(Customerlnfo ASD)
{
return(this.name.CompareTo(ASD.name));//返回按照姓名比较的结果
} 展开
{
public string id{get;set;}
public string name{get;set;}
public string address{get;set;}
public Customerlnfo(string myid,string myname,string myaddress)
{
this.id=myid;
this.name=myname;
this.address=myname;
}
public int ASV(Customerlnfo ASD)
{
return(this.name.CompareTo(ASD.name));//返回按照姓名比较的结果
} 展开
1个回答
展开全部
这个错误和泛型没有什么关系。错误出在:你的CustomInfo类继承了IComparable<T>接口,那你在类中就必须实现这个接口!
class Customerlnfo : IComparable<Customerlnfo>
{
public string id { get; set; }
public string name { get; set; }
public string address { get; set; }
public Customerlnfo(string myid, string myname, string myaddress)
{
this.id = myid;
this.name = myname;
this.address = myname;
}
public int ASV(Customerlnfo ASD)
{
return (this.name.CompareTo(ASD.name));//返回按照姓名比较的结果
}
// 必须实现 IComparable<Customerlnfo>接口
public int CompareTo(Customerlnfo other)
{
……
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询