【发布时间】:2018-10-30 23:38:42
【问题描述】:
我有一个列表,其中每个项目本身都是一个列表。 如何检查所有单个项目是否相同?
static void Main(string[] args)
{
var myList = new List<List<string>>();
var myItem1 = new List<string> { "str1", "str2" };
var myItem2 = new List<string> { "str1", "str2" };
myList.Add(myItem1);
myList.Add(myItem2);
var total = ?? // <- I'm stuck here
Console.WriteLine(total);
Console.ReadKey();
}
现在我想检查 myList 中的每个项目是否相等。 我确实尝试过这个:Check if two list have the same items,但无法解决。
【问题讨论】:
-
物品的顺序或重复是否重要?
-
我投票决定将此问题作为题外话结束,因为simple google search would bring the answer to it。提示:如果此方法不返回任何项目 - 它相等
-
当您在尝试链接答案时说“无法解决”时 - 您得到了什么结果以及您尝试了什么?
-
@AlexandruPuiu,没关系。
-
所以在您的示例中,您是否希望结果为
false,因为myList包含"str1"和"str2"(它们不相等)?