【问题描述】
C#中使用List中的Contains会非常耗时,因为使用了Equals来进行比较,效率比较低,进行复杂操作的时候能感觉到明显的卡顿
【解决方案】
扩展一个方法使用==来进行比较
public static class ListEx
{
public static bool CustomContains<T>(this IList<T> list,T t)where T: class
{
foreach (var item in list)
{
if (item == t)
{
return true;
}
}
return false;
}
}