English 中文(简体)
教派推广方法,对个案的敏感性不可行
原标题:Intersect extension method, case sensitivity not working

我试图将2个收藏品的内容进行比较。 该网络使用MTE。 为了简单起见,我发现新的和非常冷却的情况,而不是不得不ort,然后通过收集和比较项目。 sect推广方法。

似乎做了大量工作:

         Assert.AreEqual(expected.Count, actual.Intersect(expected).Count)

然而,现在我有一个需要对案件有敏感认识的测试,它打破了僵局。 我曾尝试向CuringComparer发送第二参数。 Ordinal,StringComparer.InvariantCulture, and StringComparer.CurrentCulture... no luck.

此前曾有过这种经历吗?

感谢!

EDIT:以下数据:

 Actual:
    (0) "FOO"   String
    (1) "foo"   String
    (2) "Foo"   String
    (3) "fOo"   String
    (4) "foO"   String
    (5) "BAR"   String
    (6) "BAR"   String
    (7) "BAZ"   String
    (8) "baz"   String
    (9) "foo"   String

 Expected:

    (0) "FOO"   String
    (1) "foo"   String
    (2) "Foo"   String
    (3) "fOo"   String
    (4) "foO"   String
    (5) "BAR"   String
    (6) "BAR"   String
    (7) "BAZ"   String
    (8) "baz"   String
    (9) "foo"   String

 actual.Intersect(expected, StringComparer.CurrentCulture)

    (0) "FOO"   String
    (1) "foo"   String
    (2) "Foo"   String
    (3) "fOo"   String
    (4) "foO"   String
    (5) "BAR"   String
    (6) "BAZ"   String
    (7) "baz"   String

似乎正在消除一种配对 duplicate和一种对应的BAZ。 或许有更好的办法来主张收集方法?

_EDIT2:我想Intersection()去除复制件,这就是为什么要打破。 我创立了收缴物品警戒级。 这正是我所需要的。 感谢! ——

最佳回答

为测试目的使用<条码>。

http://msdn.microsoft.com/en-us/library/bb348567.aspx” rel=“nofollow noreferer”>SequenceEqual,而不是Intersection。 教派交还了两条顺序的交汇点,即它们共有的物品。 利用sect(1、2、3}和{3、4、5}将返回。 3. 归还不实之处。

你们没有发现藏书 如欲知:

Assert.IsTrue(actual.SequenceEqual(expected))
问题回答

执行《公约》 比较:

Class StringCaseInsensitiveComparer
    Implements IEqualityComparer(Of String)
    Public Function Equals(ByVal s1 As String, ByVal s2 As String) As Boolean
        Return s1.ToLower() = s2.ToLower()
    End Function
    Public Function GetHashCode(ByVal s As String) As Integer
        Return s.GetHashCode()
    End Function
End Class

然后,将这一超载的 Inter称为:

Dim first As IEnumerable(Of TSource)
Dim second As IEnumerable(Of TSource)
Dim comparer As IEqualityComparer(Of TSource)
Dim returnValue As IEnumerable(Of TSource)

顺便提一下你刚才所作的比较。





相关问题
Is Shared ReadOnly lazyloaded?

I was wondering when I write Shared ReadOnly Variable As DataType = New DataType() Or alternatively Shared ReadOnly Variable As New DataType() Is it lazy loaded or as the instance initializes? ...

Entertaining a baby with VB.NET

I would like to write a little application in VB.NET that will detect a baby s cry. How would I get started with such an application?

Choose Enter Rather than Pressing Ok button

I have many fields in the page and the last field is a dropdown with list of values. When I select an item in a dropdown and press Enter, it doesn t do the "Ok". Instead I have to manually click on Ok ...

ALT Key Shortcuts Hidden

I am using VS2008 and creating forms. By default, the underscore of the character in a textbox when using an ampersand is not shown when I run the application. ex. "&Goto Here" is not ...

Set Select command in code

On button Click I want to Set the Select command of a Gridview. I do this and then databind the grid but it doesn t work. What am i doing wrong? protected void bttnView_Click(object sender, ...

Hover tooltip on specific words in rich text box?

I m trying to create something like a tooltip suddenly hoovering over the mouse pointer when specific words in the richt text box is hovered over. How can this be done?

热门标签