我已经搜索了一段时间,发现了这个问题的许多很好的答案,但是当我尝试模仿我的解决方案中的代码时,每个解决方案都会出错。
我正在将值传递给一个应该
- 建立 LINQ to XML 文件
- 选择档案
- 按传递给函数的值过滤
- 创建显示列表
我的代码如下:
Dim xelement As XElement = xelement.Load(get_local_data_year_path() & "\" & "PAYMENT.xml")
Dim elements = From objdata In xelement.Elements("PAYMENT")
Select New With {
.id = Trim(objdata.Element("id").Value),
.Date = objdata.Element("paymentdate").Value,
.account_id = objdata.Element("account_id").Value
}
If straccount_id.Length > 0 Then
elements.Where(Function(P As PAYMENT) P.account_id.Equals(straccount_id))
End If
Dim result = (elements).ToList
我遇到的问题是 where 子句,因为它会产生错误
Overload resolution failed because no accessible 'Where' can be called with these arguments:
Extension method 'Public Function Where(predicate As System.Func(Of <anonymous type>, Integer, Boolean)) As System.Collections.Generic.IEnumerable(Of <anonymous type>)' defined in 'System.Linq.Enumerable': Nested function does not have a signature that is compatible with delegate 'System.Func(Of <anonymous type>, Integer, Boolean)'.
Extension method 'Public Function Where(predicate As System.Func(Of <anonymous type>, Boolean)) As System.Collections.Generic.IEnumerable(Of <anonymous type>)' defined in 'System.Linq.Enumerable'.
我想我不确定当它是一个 XML 文件时如何声明 PAYMENT 以及为什么该行根本不起作用。
任何帮助,将不胜感激。如果可能,首选 VB.NET 示例。