2015-09-10 97 views
1

使用轉換器(展鵬,Telerik的,...)之後,我不能把這個表達式C#來vb.netC#表達拉姆達到VB.NET

if (afterItemRemoved != null) 
     { 
      cacheItemPolicy.RemovedCallback = x => afterItemRemoved(
       x.CacheItem.Key, 
       (T)x.CacheItem.Value); 
     } 

我曾嘗試沒有成功下列表達式(反射器8.5代展鵬Ÿconverter.telerik.com)

If (afterItemRemoved IsNot Nothing) Then 
    cacheItemPolicy.RemovedCallback = x => afterItemRemoved.Invoke(x.CacheItem.Key, DirectCast(x.CacheItem.Value, T)) 
End If 


If afterItemRemoved IsNot Nothing Then 
    cacheItemPolicy.RemovedCallback = Function(x) afterItemRemoved(x.CacheItem.Key, DirectCast(x.CacheItem.Value, T)) 
End If 
+1

您已經試過什麼樣子從原來的完全不同。爲什麼函數名稱在你的嘗試中不同? – DarkKnight

+0

是兩種類似的方法,是一種轉錄錯誤。謝謝你的評論。 –

+1

將「!=」(C#)轉換爲「>」(VB.NET)的工具肯定不是太有用。 – varocarbas

回答

3

望着文檔RemovedCallback我們可以看到,所需要的委託簽名是void方法(在VB.Net一Sub)(見CacheEntryRemovedCallback)。

所以需要lambda表達式必須是一個「子LAMBDA」而不是「功能拉姆達」

If afterItemRemoved IsNot Nothing Then 
    cacheItemPolicy.RemoveCallback = 
     Sub(x) afterItemRemoved(x.CacheItem.Key, DirectCast(x.CacheItem.Value, T)) 
End If 
+0

謝謝Sehnsucht。 –