-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Proposal] Allowance of Enumerate Local Methods #3320
Comments
There's plans to introduce Discriminated unions to C# next release. Based on the linked proposal, I would guess the following would be legal: public partial class enum Enumerate
{
Value1, Value2, Value3;
}
public partial class Enumerate
{
private Enumerate()
{
// More code here
}
} Whilst the partial is unfortunate, remember this proposal has not been fully fleshed out yet. By the time it's done I imagine you would be able to simply write: public class enum Enumerate
{
Value1, Value2, Value3;
private Enumerate()
{
// More code here
}
} |
Yeah thanks |
Would also suggest to have variables inside the enum: public enum Enumerate
{
// some values go here
public string str = "something";
} |
I think my response would be identical - based on the current proposal you would have to do that using partial, but I would hope that restriction is removed by the time this is released. |
Duplicate of #297? |
Closing as duplicate. |
Summary
In some other programming languages, like Java, it is permitted to have local methods in enumerates, for example:
Motivation
Like I said above, in Java, it is possible. Though I have used C# for quite a while, I would like to propose this feature. The current way to do so, in C#, is a little bit different, with extension methods:
As you can see, it is much longer and more complicated.
Detailed Design
Syntax
The syntax, proposed for this new feature, is as follows:
private
is ONLY accepted for its instantiation;So now, according to our syntax proposal, the proposed syntax will be like this:
The text was updated successfully, but these errors were encountered: