0
votes

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.

1

1 Answers

3
votes

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();