Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Invalid token '=>' in class, struct, or interface member declaration in c#

I’m using Visual Studio 2015. Is there a problem in the code? Please guide. I’m also still a beginner in C#.

public partial class Root : Form
{
    private BindingList<Product> list = null;
    private BindingSource bindingSource = null;

    public Root() => InitializeComponent();
}

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You are using an old version of C# that comes with Visual Studio 2015. If you can, you should upgrade to Visual Studio 2022, so that you can use language features like expression bodied constructors.

If you cannot or do not want to upgrade to the latest Visual Studio and C# versions, then the easy fix is to change the constructor like this:

public partial class Root : Form
{
    //...

    public Root()
    {
        InitializeComponent();
    }
}

As Jon Skeet noted, expression-bodied constructors are only supported in C# 7.0 and higher.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading