I am at a loss to understand why this Test would fail with Message "Assert.AreEqual failed. Expected:<2>. Actual:<1>."
[TestMethod]
public void Test()
{
char[] a1 = "abc".ToCharArray();
char[] a2 = {'a', 'b', 'c', ' ', ' '};
Assert.AreEqual(2, a2.Except(a1).Count());
}
but the following would pass:
[TestMethod]
public void Test()
{
char[] a1 = "abc".ToCharArray();
char[] a2 = {'a', 'b', 'c', ' ', 'd', ' '};
Assert.AreEqual(2, a2.Except(a1).Count());
}
Except gives you a SET which means it does not return duplicates.
See Except documentation
The Except
function returns the set difference of the two sequences - not the difference.
The space character only gets returned once.
because except finds difference of two sequences
http://msdn.microsoft.com/ru-ru/library/system.linq.enumerable.except.aspx
maybe you need something like this
var c=a2.Where(a=>a1.Contains(a)==false).Count();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With