You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Something that's been bugging me a long time. Now that C# 6 has come up with using static concept, I have decided to bring this up for discussion:
When dealing with enums we have constructs similar to the following:
DialogResultresult=DialogResult.Ok;
Now I fully understand why I have to put the first DialogResult in that declaration. But I don't understand why the enum type is required in the assignment part. If I omit it the compiler will complain, telling me that a DialogResult is expected. So if it know that we are dealing with DialogResult surely it could look in the DialogResult type and allow
DialogResultresult=Ok;
This becomes particularly handy when dealing with [Flag] enums. Would your rather type all of this:
In other words in all context where an expression of the known type is expected, you can infer the type.
If there is a conflict you have to resolve the ambiguity explicitly:
classMyClass{intLeft{get;set;}intRight{get;set;}voidSetAnchorSide(intmargin){....}voidSetAnchorSide(AnchorStylesside){ ...}voidSomeCode(){// Ambiguous - could refer to either this.Left of AnchorStyles.LeftSetAnchor(Left);// Use either of the following twoSetAnchor(AnchorStyles.Left);SetAnchor(this.Left);}}
The text was updated successfully, but these errors were encountered:
Something that's been bugging me a long time. Now that C# 6 has come up with
using static
concept, I have decided to bring this up for discussion:When dealing with enums we have constructs similar to the following:
Now I fully understand why I have to put the first
DialogResult
in that declaration. But I don't understand why the enum type is required in the assignment part. If I omit it the compiler will complain, telling me that aDialogResult
is expected. So if it know that we are dealing withDialogResult
surely it could look in theDialogResult
type and allowThis becomes particularly handy when dealing with
[Flag]
enums. Would your rather type all of this:or all of this:
In the context of the assignment, it is pretty obvious what is meant. No need to guess.
Similarly with switch statement and comparisons:
and, of course, return values:
and function calls:
In other words in all context where an expression of the known type is expected, you can infer the type.
If there is a conflict you have to resolve the ambiguity explicitly:
The text was updated successfully, but these errors were encountered: