因为我已经很久没写过代码了,所以如果我问一些愚蠢的问题,请耐心等待。
虽然 IntelliSense 在 Names 后显示 Intersect 方法,但当尝试比较两个 IEnumerables 时,我收到以下错误:
我正在尝试比较数据库查询结果和 html 中的有序列表。
'IEnumerable' 不包含 'Intersect' 的定义,并且最佳扩展方法重载 'Queryable.Intersect(IQueryable, IEnumerable)' 需要类型为 'IQueryable' 的接收器。
namespace Data.Repositories
{
public class StudentsRepository
{
public class Student
{
public string FullName { get; set; }
}
public static IEnumerable<Student> GetData(string CardNumber, string Section)
{
// FullName varchar(300) in Database
return CommonFunctions.ExecuteReader1<Student>(QryStudentSectionDetails(CardNumber, Section)).AsQueryable();
}
}
}
namespace Tests.ActionsLibrary.StudentPaper
{
public class StudentActions:TestBase
{
bool IsMatch = false;
// Get Names from DataBase
IEnumerable<Student> Names = GetData(CardNumber, Section);
// Get Names from Ordered list in HTML
IEnumerable<IWebElement> OrderedList = driver.FindElements(By.XPath("//li[@ng-repeat='Names']"));
if (Names.Count() == OrderedList.Count() && Names.Intersect(OrderedList).Count() == OrderedList.Count()) // The error is shown here.
{ IsMatch = true; }
我想知道我做错了什么,非常感谢任何帮助。谢谢。
最后代码看起来像这样:
IEnumerable<string> Names = GetData(CardNumber, Section).Select(s => s.FullName);
IEnumerable<string> OrderedList = driver.FindElements(By.XPath("//li[@ng-repeat='Names']")).Select(i => i.Text);
非常感谢您的帮助。
Students
和IWebElements
之间会有什么交集?除此之外,你可能还有其他问题需要解决,但这确实是你应该注意的事情。 - SimpleVar