linq得到内在属性

时间:2012-05-21 09:54:28

标签: xml vb.net linq

我想做的是,我有以下xml:

  

邮政编码id =“E20 2AP”从=“test1”到=“test2”/>

我试图搜索邮政编码ID,然后从我的代码中获取来自该ID的文本:

    Public Shared Function GetFromDate(ByVal PostCode As String) As String
    Dim LoadToAddresses = From ex In doc.Descendants.Elements("Postcode") Select New With {.accountName = ex.Attribute("id").Value, .datefrom = ex.Attribute("from").Value}
    For Each x In LoadToAddresses
        Dim datefrom = (From p In LoadToAddresses Where p.accountName = PostCode Select New With {.datefrom = p.datefrom}).Single
        Return datefrom.ToString
    Next
End Function

这可行,但它会返回:

  

{datefrom = test}

我只想让它说“测试”

感谢

1 个答案:

答案 0 :(得分:1)

'Return datefrom.ToString
Return datefrom.datefrom

或:

'Dim datefrom = (From p In LoadToAddresses Where p.accountName = PostCode Select New With {.datefrom = p.datefrom}).Single
Dim datefrom = (From p In LoadToAddresses Where p.accountName = PostCode Select p.datefrom}).Single