しばらく検索したところ、この質問に対する多くの優れた回答が見つかりましたが、ソリューションのコードを模倣しようとすると、各ソリューションでエラーが発生します。
関数に値を渡す必要があります
- XML ファイルへの LINQ を確立する
- フィールドを選択
- 関数に渡された値でフィルタリングする
- 表示するリストを作成する
私のコードは次のとおりです。
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 の例が優先されます。