我有一门课如下
class WarningClass
{
public string SqlEyeWarning { get; set; }
public string FileName { get; set; }
}
它的填充如下
List<WarningClass> lstWarningClass1 = new List<WarningClass>();
lstWarningClass1.Add(new WarningClass { FileName = "a.sql", SqlEyeWarning = "SD001: order mismatch or it should be ON." });
lstWarningClass1.Add(new WarningClass { FileName = "a.sql", SqlEyeWarning = "SD001: order mismatch or it should be ON." });
lstWarningClass1.Add(new WarningClass { FileName = "c.sql", SqlEyeWarning = "SD009: Missing or order mismatch of Grant statement." });
可以看出,第一条和第二条记录存在重复条目。
如何获得唯一条目。
最终输出
FileName = "a.sql", SqlEyeWarning = "SD001: order mismatch or it should be ON."
FileName = "c.sql", SqlEyeWarning = "SD009: Missing or order mismatch of Grant statement."
如果我这样做lstWarningClass1.Distinct()
,那是行不通的