File Scoped Namespace Class #7944
Replies: 3 comments
-
I don't see any benefit in this; it only eliminates two curly braces and one indentation level. An analyzer might be more suitable than a language feature for enforcing one type per file. |
Beta Was this translation helpful? Give feedback.
0 replies
-
It ends up simplifying the language a lot, especially for beginners, by linking each class per file, making it more user-friendly, for example: No namespaceExample.cs class Example;
public string GetExample()
{
} Program.cs var example = new Example();
Console.WriteLine(user.GetExample()); With namespaceExample.cs namespace class MyApp.Example;
public string GetExample()
{
} Program.cs using MyApp;
var example = new Example();
// Or:
var example = new MyApp.Example();
Console.WriteLine(user.GetExample()); The teaching is much better. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Duplicate of #928. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
C# is a wonderful language and I really love it so much, and something that I particularly like a lot is that it is a language that, in addition to being extremely powerful, does not stop in time and is always bringing new features, facilitating how we code and not getting stuck. behind new languages.
Something simply incredible were the top-level instructions, where instead of having to do something like:
You can do just this:
With that in mind, something I would like to suggest a new feature for a few reasons:
It would be something like
File Scoped Namespace
but for classes. When used, only 1 class and 1 namespace could be defined in the entire file:Example 1:
Visual Studio 2022
Code
Example 2:
Visual Studio
Code
Example 3:
Visual Studio
Code
Separate namespace and class
Another suggestion, if it is better to separate namespace and class:
Visual Studio
Code
Or until:
Visual Studio
Code
Translated by Google Translate.
It ends up simplifying the language a lot, especially for beginners, by linking each class per file, making it more user-friendly, for example:
No namespace
Example.cs
Program.cs
With namespace
Example.cs
Program.cs
The teaching is much better.
Beta Was this translation helpful? Give feedback.
All reactions