Skip to content

Instantly share code, notes, and snippets.

@zhaopan
Last active March 1, 2023 07:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zhaopan/7c2d91d2c6d1d11eb828c3ac9138daec to your computer and use it in GitHub Desktop.
Save zhaopan/7c2d91d2c6d1d11eb828c3ac9138daec to your computer and use it in GitHub Desktop.
ListComparer
public class MaterielCodesComparer : IEqualityComparer<EntMaterielCodes>
{
public bool Equals(EntMaterielCodes x, EntMaterielCodes y)
{
if (Object.ReferenceEquals(x, y)) return true;
return x != null && y != null && x.RFIDCode == y.RFIDCode && x.UniqueCode == y.UniqueCode;
}
public int GetHashCode(EntMaterielCodes obj)
{
int hashStudentId = obj.RFIDCode.GetHashCode();
int hashScore = obj.UniqueCode.GetHashCode();
return hashStudentId ^ hashScore;
}
}
public class Sample
{
private void Run()
{
var oldArr = codes.Select(x => new EntMaterielCodes { RFIDCode = x.RFIDCode, UniqueCode = x.UniqueCode }).ToArray();// 以前的rfid码
var newArr = newCodes.Select(x => new EntMaterielCodes { RFIDCode = x.RFID, UniqueCode = x.UniqueCode }).ToArray(); // 当前传入的rfid码
// 亏
var deficitList = oldArr.Except(newArr, new MaterielCodesComparer());
// 盈
var surplusList = newArr.Except(oldArr, new MaterielCodesComparer());
// 正常
var intersectList = newArr.Intersect(oldArr, new MaterielCodesComparer());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment