一些非常基本的东西似乎从我的记忆中消失了。
Dim foo As New Dictionary(Of String, String)
foo.Add("key", Nothing)
foo.Add("key2", "something")我希望得到一个IDictiorany(字符串,字符串),其中只包含具有非空值的元素。我以为这样就行了:
foo.Where(Function(x) Not String.IsNullOrEmpty(x.Value))但这最终是错误的类型。添加:
.ToDictionary(Function(x) x.Key)也没有任何帮助。有什么建议吗?
发布于 2008-12-12 15:10:52
啊..。回答了我自己的问题。我会把它留下来,以防它对其他人有用。
Dim foo As Dictionary(Of String, String)
foo.Add("k1", Nothing)
foo.Add("k2", "something")
Dim IDictionary(Of String, String) res = foo _
.Where(Function(x) Not String.IsNullOrEmpty(x.Value)) _
.ToDictionary(Function(x) x.Key, Function(y) y.Value)https://stackoverflow.com/questions/362999
复制相似问题