Last active
March 1, 2023 07:02
-
-
Save zhaopan/7c2d91d2c6d1d11eb828c3ac9138daec to your computer and use it in GitHub Desktop.
ListComparer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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