在VB.NET中使用LINQ的ForEach与匿名方法
发布时间:2020-12-17 00:10:45 所属栏目:大数据 来源:网络整理
导读:我试图用VB.NET中的LINQ ForEach扩展替代经典的For Each循环 Dim singles As New List(Of Single)(someSingleList) Dim integers As New List(Of Integer) For Each singleValue In singles integers.Add(CInt(Math.Round(singleValue))) Next singleValue
我试图用VB.NET中的LINQ ForEach扩展替代经典的For Each循环
Dim singles As New List(Of Single)(someSingleList) Dim integers As New List(Of Integer) For Each singleValue In singles integers.Add(CInt(Math.Round(singleValue))) Next singleValue 也许这样吗? singles.ForEach(Function(s As [Single]) Do ??? 如何正确使用匿名方法(即不声明新功能)?
尝试这个:
singles.ForEach(Sub(s As [Single]) integers.Add(CInt(Math.Round(s)))) 您需要一个Sub,因为您的For Each循环的正文不返回值. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |