Mat*_*att 3 .net c# list iequatable iequalitycomparer
我有一个叫做的课
MyClass
Run Code Online (Sandbox Code Playgroud)
这个类继承IEquatable并实现等于我需要它的方式.(含义:当我在代码中单独比较两个MyClass tyupe对象时,它可以工作)
然后我创建两个List:
var ListA = new List<MyClass>();
var ListB = new List<MyClass>();
// Add distinct objects that are equal to one another to
// ListA and ListB in such a way that they are not added in the same order.
Run Code Online (Sandbox Code Playgroud)
当我去比较ListA和ListB时,我应该得到真的吗?
ListA.Equals(ListB)==true; //???
Run Code Online (Sandbox Code Playgroud)
请尝试以下方法
ListA.SequenceEquals(ListB);
Run Code Online (Sandbox Code Playgroud)
SequenceEquals是Enumerable类中可用的扩展方法.这在C#3.5项目中是可用的,因为它随System.Linq一起提供
| 归档时间: |
|
| 查看次数: |
431 次 |
| 最近记录: |