当前位置:网站首页>Explain the difference set, intersection set and union set of complex type set in detail.Net

Explain the difference set, intersection set and union set of complex type set in detail.Net

2022-07-28 15:31:00 InfoQ

Preface
As the title says , stay
http://ASP.NET
Application development , When comparing two sets   We use Microsoft IEnumerable Packaged  
Except/Intersect/Union 
take   Difference set / intersection / Combine   The method is very convenient ; But for those who are not familiar with it , When encountering the request, include the reference type ( It doesn't contain string) When I gather, I feel very distressed ; Next, I will take you to learn how to get it through Microsoft's own method ** A collection of complex types ** The difference between the set 、 intersection 、 Combine .
scene
Here is the scene , I have the following two students .
null
Generate two entity sets ;
Now let's take the intersection / Difference set / Combine
Complete call example (.NET Core):
null
  
A closer look at the above output is obviously wrong , This involves complex type comparison , Please look at the code. :
Normal class we declare
null
Because we want to compare reference types , Because in contrast, divide string Outside the reference type ,
By default, the comparison of other reference types is the heap address of the comparison
, So we need to inherit an interface to implement a custom comparison scheme  
IEqualityComparer<T>
&nbsp; Generic interfaces are as follows :( Here we take age and name as the comparison conditions )
null
After modifying the class, there is the most important point : Is to modify the method of comparison ( It is equivalent to declaring a custom comparator to the method )
null
So far, the comparison of reference types has been completed , The condition method of the comparator can be adjusted according to the demand , If there are shortcomings , I hope you can correct me more !!!
Only try to make yourself better , To live a better life
原网站

版权声明
本文为[InfoQ]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/209/202207281430461408.html