我試圖將下面的C#代碼轉換爲VB.NET。問題在於lambda表達式。將C#Lambda轉換爲VB.NET
public class UserStore
{
private readonly IDatabaseFactory _databaseFactory;
private DataContext _db;
protected DataContext Db => _db ?? (_db = _databaseFactory.GetDataContext());
public UserStore(IDatabaseFactory databaseFactory)
{
_databaseFactory = databaseFactory;
}
}
以下是我所轉換的代碼:
Public Class UserStore
Private ReadOnly _databaseFactory As IDatabaseFactory
Private _db As DataContext
Protected Db As DataContext = Function() As DataContext
If _db Is Nothing Then
_db = _databaseFactory.GetDataContext()
End If
Return _db
End Function
Public Sub New(databaseFactory As IDatabaseFactory)
_databaseFactory = databaseFactory
End Sub
End Class
出於某種原因,轉換後的拉姆達給出了錯誤Lambda expression cannot be converted to 'DataContext' because 'DataContext' is not a delegate type.
誰能告訴我我在做什麼這裏錯了嗎?
這不是拉姆達的只是一小段路。它是表達酒體的財產。 – PetSerAl