0

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();
}
Julian
  • 5,290
  • 1
  • 17
  • 40
roy
  • 693
  • 2
  • 11
  • 2
    You need to check the c# version of the project. Expression bodied members (`public Root() => InitializeComponent();`) was introduced in c# 6. If the c# version is lower than 6, you can't use expression bodied members. – Zohar Peled Jul 06 '23 at 07:20
  • 5
    "I'm using Visual Studio 2015" - then you'll be using a very old version of C#. I strongly recommend that you upgrade to VS 2022. – Jon Skeet Jul 06 '23 at 07:21
  • 3
    @ZoharPeled: More than that, this is an expression-bodied *constructor*, and that was introduced in C# 7. – Jon Skeet Jul 06 '23 at 07:23

1 Answers1

2

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.

Julian
  • 5,290
  • 1
  • 17
  • 40