比较C#中的两个字符串数组 [英] Comparing two string arrays in C#

查看:66
本文介绍了比较C#中的两个字符串数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我们有5个这样的字符串数组:

Say we have 5 string arrays as such:

string[] a = {"The","Big", "Ant"};
string[] b = {"Big","Ant","Ran"};
string[] c = {"The","Big","Ant"};
string[] d = {"No","Ants","Here"};
string[] e = {"The", "Big", "Ant", "Ran", "Too", "Far"};

有没有一种方法可以将这些字符串彼此比较,而无需在C#中循环通过它们,从而仅a和c会产生布尔值true?换句话说,所有元素必须相等并且数组必须具有相同的大小?同样,如果可能的话,不使用循环.

Is there a method to compare these strings to each other without looping through them in C# such that only a and c would yield the boolean true? In other words, all elements must be equal and the array must be the same size? Again, without using a loop if possible.

推荐答案

您可以使用Linq:

bool areEqual = a.SequenceEqual(b);

这篇关于比较C#中的两个字符串数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆