[英]C# List not comparing with equals operator
I am comparing two lists in C#. 我正在用C#比较两个列表。 Here is the basic code 这是基本代码
List<string> expectedTabs = new List<string>() { "Batch", "Card Services", "ReportingXXXXX" };
List<string> actualTabs = new List<string>() { "Batch", "Card Services", "Reporting" };
string [] text = new string[actualTabs.Count];
int i = 0;
foreach (IWebElement element in actualTabs)
{
text[i++] = element;
Console.WriteLine("Tab Text : " + text[i - 1]);
}
for(int x = 0; x < actualTabs.Count; x++)
{
Assert.IsTrue(expectedTabs.Count == actualTabs.Count); //this gives equal count
Console.WriteLine(expectedTabs[x] + " :: " + actualTabs[x]);
expectedTabs[x].Equals(actualTabs[x]); //Gives wrong result here
Console.WriteLine(expectedTabs.GetType()); //returns type as collection.list
}
Now the equal should return false when comparing the last element [ReportingXXXXX and Reporting]
in both the lists, but it just gives the result as equal. 现在,当比较两个列表中的最后一个元素[ReportingXXXXX and Reporting]
时,equal应该返回false,但是它只给出相等的结果。 I am not sure if I need to use something else here. 我不确定是否需要在这里使用其他内容。
reducing your code to what I think is the relevant bits... 将您的代码减少到我认为是相关的位...
var expectedTabs = new List<string>() { "Batch", "Card Services", "ReportingXXXXX" };
var actualTabs = new List<string>() { "Batch", "Card Services", "Reporting" };
for (var x = 0; x < actualTabs.Count; x++)
{
var equal = expectedTabs[x].Equals(actualTabs[x]); //Gives wrong result here
Console.WriteLine(equal);
}
This produces 这产生
True
True
False
Where are you seeing the wrong result? 您在哪里看到错误的结果?
Your code / comparison works fine. 您的代码/比较工作正常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.