Dot target-typed member access #4479
Unanswered
JesperTreetop
asked this question in
Language Ideas
Replies: 2 comments 4 replies
-
There is a proposal that is marked as championed (but assigned to a language design member who is no longer with the team): #2926 My understanding is that it would enable this syntax: var r = string.Compare("a0", "A0", InvariantCulture, IgnoreCase | IgnoreWidth); |
Beta Was this translation helpful? Give feedback.
2 replies
-
This comment by @gafter in another proposal highlights that there would be a syntactical conflict/ambiguity with the conditional member access operator (ie |
Beta Was this translation helpful? Give feedback.
2 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.
-
With target-typed
new
as the latest example, there is an existing notion in the language of inferring the natural/effective/expected type from a location. If you're passing a parameter to a method, you can saynew()
and C# knows which type you mean; same with initializing or assigning to a variable or member.So, with that in mind, how about also allowing
.xyz
to mean the member access of<inferred type>.xyz
? This would allow making references to enum members and static members (factory methods, properties or constants for singleton/well-known instances) simpler, in cases where the type is already apparent or at least well-defined.As an example, the following code:
could instead be simply:
There was a previous discussion involving this, but using a keyword before the dot/period. Since not using anything to trigger this would potentially change the meaning of any identifier anywhere, the previous discussion considered using
var
ordefault
before the dot. But just using dot is not ambiguous or backwards incompatible -real_literal
s can start with dots, but they have to be followed by a digit, whereasidentifier
s can't start with digits. No legal program would change meaning or stop being legal.Beta Was this translation helpful? Give feedback.
All reactions