我有两个清单:
ListA:
"Brown"
"Green"
"Yellow"
"Orange"
ListB:
"Yellow"
"Orange"
Run Code Online (Sandbox Code Playgroud)
如果ListA或ListB彼此包含,我想返回true.在这种情况下,ListB是ListA的一部分.ListB不一定是小的.
我能想到的唯一解决方案是双方都做Union,即首先使用ListB进行ListA,然后使用ListA进行ListB,当且仅当两者都为真时返回true.
这是最好的方法,还是其他方式吗?
我希望有一个Linq解决方案
你可以尝试:
int count = ListA.Intersect(ListB).Count();
if ((count == ListA.Count()) || (count == ListB.Count())) {
// One list contains other
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
535 次 |
| 最近记录: |