gpt4 book ai didi

c# - 在 C# 中,查看一个列表是否包含另一个列表的最佳方法是什么?

转载 作者:行者123 更新时间:2023-11-30 19:17:04 36 4
gpt4 key购买 nike

如果我有一个字符串列表,确定另一个列表中的每个元素是否包含在此列表中的最佳方法是什么。例如:

List<string> list = new List<string>();
list.Add("Dog");
list.Add("Cat");
list.Add("Bird");

List<string> list2 = new List<string>();
list.Add("Dog");
list.Add("Cat");

if (list.ContainsList(list2))
{
Console.Write("All items in list2 are in list1")
}

我正在尝试确定是否存在类似“ContainsList”的方法?

最佳答案

if (!list2.Except(list).Any())

关于c# - 在 C# 中,查看一个列表是否包含另一个列表的最佳方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19647735/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com