I am a new to C# and .NET 9. I am trying to execute the following program I found from the official MS tutorial - Create record types
public record Point(int X, int Y);
public static void Main()
{
Point pt = new Point(1, 1);
var pt2 = pt with { Y = 10 };
Console.WriteLine($"The two points are {pt} and {pt2}");
}
in my VS Code. When I run dotnet build, I get the following error :
Restore complete (1.1s)
TestProject failed with 2 error(s) (1.0s)
/workspaces/workspace/c#/CsharpProjects/TestProject/Program.cs(3,1): error CS8803: Top-level statements must precede namespace and type declarations.
/workspaces/workspace/c#/CsharpProjects/TestProject/Program.cs(3,1): error CS0106: The modifier 'public' is not valid for this itemBuild failed with 2 error(s) in 3.5s
However, the same program available in the web tutorial works fine when I click on run (green button on top right).
I would like to know why it does not work locally? And how can I fix it?