以下のVB.netの構文は何ですか?linq to xml(C#からvb.netへの変換)
var list = xd.Descendants("product")
.Select(element =>new
{
Title = element.Attribute("title").Value,
Duration = element.Element("duration").Value
}).ToList();
以下のVB.netの構文は何ですか?linq to xml(C#からvb.netへの変換)
var list = xd.Descendants("product")
.Select(element =>new
{
Title = element.Attribute("title").Value,
Duration = element.Element("duration").Value
}).ToList();
これを試してみてください:
Dim list =
From element In xd.Descendants("product")
Select New With { _
.Title = element.Attribute("title").Value, _
.Duration = element.Element("duration").Value }
あなたはあなただけの基礎となる拡張機能を使用することができ、LINQの構文を使用する必要はありません。
Dim list = xd.Descendants("product"). _
Select(Function(element) _
New With { _
.Title = element.Attribute("title").Value, _
.Duration = element.Element("duration").Value _
}). _
ToList()
ありがとうKeiths - それは私をソートしました – Sreedhar
あなたはVBを使用している場合があり、このための構文的な砂糖:
Dim list =
From element In xd...<product>
Select New With { _
.Title = [email protected], _
.Duration = element.<duration>.Value }
niそれは、ドキュメント用のxsdを持っていれば(そして1つまたは複数のxmlドキュメントからそれを推測してビジュアルスタジオで作成することもできます)、名前空間と同じようにインポートすることができ、Visual Studioからインテリセンスが得られますあなたの質問を書くときに完了してください。
いくつかの参照:xd.Descendantsで=(xから 薄暗いリスト1( "製品")_ :件まで
CStr関数は何ですか? @ titleは文字列を返しますか? – CoderDennis
それは絶対に真実です、なぜ私はそこに置くのですか? –
ガット何か。新しい要素を追加するには、ToList()を使用します。 「期間」を含める必要があります。 – Sreedhar