Distinct自定义时出错了!!大家帮我看看!
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataClassesDataContext pa = new DataClassesDataContext();
var sel = from p in pa.Course select p.Creator;
GridView1.DataSource = sel.Distinct(new BusinessObjComparer()); GridView1.DataBind();
}
}
public class BusinessObj
{
public string createtime;
public string crsname;
}
public class BusinessObjComparer : IEqualityComparer<BusinessObj>
{
public bool Equals(BusinessObj source, BusinessObj dest)
{
return source.crsname == dest.crsname;
}
public int GetHashCode(BusinessObj obj)
{
return obj.crsname.GetHashCode();
}
}
}
这样写了,但是红色的地方出错错误了!大大们帮我看看
------解决方案--------------------
var sel = from p in pa.Course select new BusinessObj{crsname=p.crsname,createtime=p.createtime};
------解决方案--------------------
http://msdn.microsoft.com/en-us/library/bb338049.aspx
------解决方案--------------------
应该是自定义的 BusinessObjComparer 方法有问题,参考一下上面的msdn.