博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Linq 等式运算符:SequenceEqual
阅读量:4631 次
发布时间:2019-06-09

本文共 1783 字,大约阅读时间需要 5 分钟。

检查元素的数量,每个元素的值及两个集合中元素的顺序是否相等,3个方面都相等则为true,否则为false

 

IList
strList1 = new List
(){
"One", "Two", "Three", "Four", "Three"}; IList
strList2 = new List
(){
"One", "Two", "Three", "Four", "Three"}; bool isEqual = strList1.SequenceEqual(strList2); // returns trueIList
strList1 = new List
(){ "One", "Two", "Three", "Four", "Three"}; IList
strList2 = new List
(){ "Two", "One", "Three", "Four", "Three"}; bool isEqual = strList1.SequenceEqual(strList2); // returns false//如果是引用类型,则比较的是引用Student std = new Student() { StudentID = 1, StudentName = "Bill" }; IList
studentList1 = new List
(){ std }; IList
studentList2 = new List
(){ std }; bool isEqual = studentList1.SequenceEqual(studentList2); // returns true Student std1 = new Student() { StudentID = 1, StudentName = "Bill" };Student std2 = new Student() { StudentID = 1, StudentName = "Bill" }; IList
studentList3 = new List
(){ std1}; IList
studentList4 = new List
(){ std2 }; isEqual = studentList3.SequenceEqual(studentList4);// returns false//在上面的示例中,studentList1和studentList2包含相同的学生对象std。 所以studentList1.SequenceEqual(studentList2)返回true。 但是,stdList1和stdList2包含两个独立的学生对象std1和std2。 //所以现在,stdList1.SequenceEqual(stdList2)将返回false.//要比较复杂类型的两个集合的值,您需要实现IEqualityComperar
接口,如下所示class StudentComparer : IEqualityComparer
{ public bool Equals(Student x, Student y) { if (x.StudentID == y.StudentID && x.StudentName.ToLower() == y.StudentName.ToLower()) return true; return false; } public int GetHashCode(Student obj) { return obj.GetHashCode(); }}// following returns truebool isEqual = studentList1.SequenceEqual(studentList2, new StudentComparer());

 

转载于:https://www.cnblogs.com/refuge/p/8151216.html

你可能感兴趣的文章
http://forum.jquery.com/topic/file-upload-ajaxsubmit-sends-response-to-wrong-window-in-ie
查看>>
php的文件下载
查看>>
easyui的增删改
查看>>
Sql Server数据库性能优化之索引
查看>>
【Android UI】 Shape详… 分类: ...
查看>>
MFC 屏幕截图(libjpeg bmp转jpg)
查看>>
jQuery中 wrap() wrapAll() 与 wrapInner()的区别
查看>>
第二阶段冲刺第二天
查看>>
JS字符串转换成json对象。。。。
查看>>
yaml语法三大规则
查看>>
【HANA系列】SAP HANA的特点总结
查看>>
修改选中文字的背景色
查看>>
【CodeForces - 546C】Soldier and Cards (vector或队列)
查看>>
Ubuntu 18.04 初始化(server版本 )
查看>>
【BZOJ-1449&2895】球队收益&球队预算 最小费用最大流
查看>>
TCP与UDP
查看>>
FolderSync :The various features and how to use them
查看>>
LPC43xx SGPIO DMA and Interrupts
查看>>
《剑指offer》面试题16—反转链表
查看>>
multiprocessing模块
查看>>