如何比较在C#中的数组? [英] How to compare arrays in C#?

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

问题描述


  

可能重复:结果
  最简单的比较C#阵列方式


我如何在C#中比较两个数组?

我用下面的code,但它的结果是假的。我期待这是真的。

  Array.Equals(childe1,grandFatherNode);


解决方案

您可以使用Enumerable.SequenceEqual()在System.Linq的为内容的数组中比较

 的isEqual布尔= Enumerable.SequenceEqual(目标1,TARGET2);

Possible Duplicate:
Easiest way to compare arrays in C#

How can I compare two arrays in C#?

I use the following code, but its result is false. I was expecting it to be true.

Array.Equals(childe1,grandFatherNode);

解决方案

You can use the Enumerable.SequenceEqual() in the System.Linq to compare the contents in the array

bool isEqual = Enumerable.SequenceEqual(target1, target2);

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

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