我有2個foreach循環和我試圖將其轉換成一個LINQ的:的foreach到LINQ
Dim result As Type = Nothing
For Each AssemblyItem As Reflection.Assembly In AppDomain.CurrentDomain.GetAssemblies
For Each typeItem As Type In AssemblyItem.GetTypes
If myClass.FullName = typeItem.FullName Then
result = typeItem
Exit For
End If
Next
If Not IsNothing(result) Then
Exit For
End If
Next
目前我有:
result = AppDomain.CurrentDomain.GetAssemblies()
.ForEach(Sub(x As Reflection.Assembly)
x.GetTypes().ForEach(Sub(t As Type)
t.FullName = catalogEntity))
我也試圖與另一種方法用沒有運氣:
result = AppDomain.CurrentDomain.GetAssemblies()
.Select(Sub(x) x.GetTypes()
.Select(Function(y) y.GetType())
.Where(Function(z) z.FullName.Equals(catalogEntity.FullName))).FirstOrDefault()
但我發現了以下錯誤:
Argument not specified for parameter 'action' of 'Public Shared Sub ForEach(Of T)(array() As T, action As System.Action(Of T))'
任何幫助將不勝感激,提前致謝!
'ForEach'是一個非常不LINQ(就是一個字是什麼?現在)要做的事情。它存在於'List'中,而不是在LINQ擴展方法中。請參閱http://blogs.msdn.com/b/ericlippert/archive/2009/05/18/foreach-vs-foreach.aspx –
2013-04-27 01:50:19
@TimS。也嘗試了非ForEach方法,但它給了我一個空值 – Luis 2013-04-27 01:55:26