I've a singleton class like,
public sealed class MainWindow
{
public Form MainWindowContainer { get; set; }
private static readonly Lazy<MainWindow> _mainWindow = new Lazy<MainWindow>(() => new MainWindow());
// Error on this line
public static MainWindow Instance => _mainWindow.Value;
private MainWindow()
{
MainWindowContainer = Host.Local.FindSingle<Form>(GenericProperties.MainWindow);
}
}
On compiling, I get error as "invalid token ';' in class struct or interface member declaration". Please help.
you cannot define a property getter as a lambda, Just change to a getter property
public static MainWindow Instance
{
get { return _mainWindow.Value; }
}
or change to a Lambda Function
public static Func<MainWindow> Instance => _mainValue.Value;
Depending on how you want to access it
var win = MainWindow.Instance;
// or
var win = MainWindow.Instance();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.