0

我有一个将 aNameValueColletion转换为IDictionary. 我将如何在功能上编写这个(使用Select等而不是循环)?

<Extension()>
Public Function ToDictionary(ByVal source As NameValueCollection)
        As IDictionary(Of String, String)
    Dim ret = New Dictionary(Of String, String)
    Dim keys = source.Keys
    For Each key In keys
        Dim sKey = TryCast(key, String)
        Dim sVal = TryCast(source(key), String)
        If sKey Is Nothing OrElse sVal Is Nothing Then Continue For
        ret(sKey) = sVal
    Next
    Return ret
End Function
4

1 回答 1

3
Return source.Cast(Of String)().
             ToDictionary(Function(key) key, Function(key) source(key))
于 2013-01-15T16:08:43.417 回答