比较两个 List<string>为了平等 [英] Comparing two List&lt;string&gt; for equality

查看:20
本文介绍了比较两个 List<string>为了平等的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

除了一个接一个地遍历元素之外,我如何比较两个字符串列表的相等性(在 .NET 3.0 中):

Other than stepping through the elements one by one, how do I compare two lists of strings for equality (in .NET 3.0):

失败:

// Expected result.
List<string> expected = new List<string>();
expected.Add( "a" );
expected.Add( "b" );
expected.Add( "c" );

// Actual result
actual = new List<string>();
actual.Add( "a" );
actual.Add( "b" );
actual.Add( "c" );

// Verdict
Assert.IsTrue( actual == expected );

推荐答案

许多测试框架都提供了 CollectionAssert 类:

Many test frameworks offer a CollectionAssert class:

CollectionAssert.AreEqual(expected, actual);

例如 MS 测试

这篇关于比较两个 List<string>为了平等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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