c#检查列表中的所有字符串是否相同

hs2*_*s2d 3 c# linq

可能重复:
检查列表中的所有项目是否相同

我有一个清单:

{string, string, string, string}
Run Code Online (Sandbox Code Playgroud)

我需要检查此列表中的所有项是否相同然后返回true,否则返回false.

我可以用LINQ做到这一点吗?

Dan*_*rth 20

var allAreSame = list.All(x => x == list.First());
Run Code Online (Sandbox Code Playgroud)