如何在VB.net中写这个lambda选择方法?
发布时间:2020-12-17 00:10:23 所属栏目:大数据 来源:网络整理
导读:因为我试过这个: Dim exampleItems As Dictionary(Of String,String) = New Dictionary(Of String,String)Dim blah = exampleItems.Select (Function(x) New (x.Key,x.Value)).ToList 'error here 但是我收到一个语法错误,所有我在C#中看到的例子. 这将是:
因为我试过这个:
Dim exampleItems As Dictionary(Of String,String) = New Dictionary(Of String,String) Dim blah = exampleItems.Select (Function(x) New (x.Key,x.Value)).ToList 'error here 但是我收到一个语法错误,所有我在C#中看到的例子.
这将是:
Dim blah = exampleItems.Select (Function(x) New With { .Key = x.Key,.Value = x.Value }).ToList 有关详细信息,请参阅Anonymous Types.(根据使用情况,您可能还需要使用Key keyword标记键或值.) 就是说,Dictionary(Of TKey,Of TValue)已经是一个IEnumerable(OfValuePair(TKey,Of TValue)),所以你也可以做: Dim blah = exampleItems.ToList 并且您将有一个KeyValuePair列表,它已经有一个Key和Value属性.这真的意味着没有必要使匿名类型. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |