Class declarations without curly braces #4722
-
This idea is similar to #4348 but this is for class declarations. I want to declare classes without curly braces: namespace ConsoleApp;
public static class HelperClass;
public static void WriteLine(string text, ConsoleColor color) {
Console.ForegroundColor = color;
Console.WriteLine(text);
} with constructor, fields, and properties: namespace Foo;
public class Bar;
public Bar(int field, int property) {
_field = field;
Property = property;
}
private int _field = 0;
public int Property { get; set; } with nested classes: namespace Foo;
public class Bar;
public class Baz {
} This syntax will be very helpful for writing minimal APIs demonstrated in this ASP.NET Community Standup: https://www.youtube.com/watch?v=enAskgcF0c0 |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 20 replies
-
This makes things very ambiguous. For example, this is already legal today: |
Beta Was this translation helpful? Give feedback.
-
We explicitly considered this in the design for #137, and rejected it as something we're not interested in. |
Beta Was this translation helpful? Give feedback.
-
I am coming from #8501. I read the arguments. I don't see how If this change is difficult, one thing comes to my mind. Preprocessors. Or even code generators (as mentioned in the linked thread). When someone writes I might die and not see those days. But I can assure everyone reading this post that someday in the future, this feature will exist in C#, or it will go out of the industry. The reason? simplicity. |
Beta Was this translation helpful? Give feedback.
-
I just found this Never Nester video. I think the whole world stands on one side, and less nesting is better. |
Beta Was this translation helpful? Give feedback.
This makes things very ambiguous. For example, this is already legal today:
public record Foo();
Now it becomes less clear if;
terminates a type, or groups over the remainder of the file.