簡體   English   中英

c#將lambda表達為vb.net

[英]c# Expression lambda to vb.net

在使用轉換器(Redgate,Telerik,...)之后,我無法將此表達式c#轉換為vb.net

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

我試過以下表達式沒有成功(Reflector 8.5 de RedGate y 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

查看RemovedCallback的文檔,我們可以看到所需的委托簽名是一個void方法(VB.Net中的一個Sub )(參見CacheEntryRemovedCallback )。

所以lambda表達式必須是“Sub Lambda”而不是“Function lambda”

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM