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

Visual Studio 2022 file-scoped namespace issue

So I have VS 2022 and am trying to learn C#.

I am getting an error of Feature

‘file-scoped namespace’ is not available in C# 7.3 Please use language
10.0 or greater.

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

I found where one goes to Options>Code Style> Text Editor and change to File-scoped. Did that.

When I create my solution, I chose Blank Solution
I then added an empty project using .NET framework 4.8
Next I added a code file
Finally I add the following:

namespace Averages;

public static class TestClass
{
 
}

And I get the error. What in the world am I missing? I’m stumped.
Edit: I just checked. I have .NET 7.0

>Solution :

You could solve this by:

namespace Averages 
{ 
   public static class TestClass
   {
 
   }
}

since Framework 4.8 doesn’t allow File-scoped names, so the class should be "inside" the namespace.

But if you are learning, I would suggest don’t use empty blank, syntax could be a bit different, but in learning mode this bit means a lot and you will found examples of code that often doesn’t specify the syntax.

You could also try your code at Fiddle DOT NET https://dotnetfiddle.net/

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