Proposal: Stronger type Inference for generics calls #11359
Labels
Area-Language Design
Feature Request
Resolution-Duplicate
The described behavior is tracked in another issue
So today, C# can infer the type from the context for types like this:
Now, when it comes to generics, say we have the following class:
When we are creating
Foo
we must satisfy the generic argument and provide the type explicitly like this:Now, in C# 7 there's a new feature to allow C# to infer the type from the argument or whatever context it might be when the type is known instead of specifying the the actual type explicitly like this (which is just beautiful imo):
So what I'm proposing is the ability to have stronger type inference for generics calls this means you no longer need to satisfy the type argument because it would be inferred by the compiler so in the future we might have the ability to write the following code instead of the above:
With my proposal the following will also be allowed so this is an addition to the C# 7.0 feature even though the C# 7.0 feature is more succinct:
When it comes to overload resolution in cases like this:
I don't know what's the best approach to go with here but I'd assume it should pick the generic constructor over anything else.
The aim here is to make the code more readable and less explicit when it makes sense, in my opinion whether something is generic or not shouldn't concern the person that reads the code.
It's not like we handle things differently if something is generic, we just write it differently and I guess we can make it look like a normal code without all the verbosity and ceremony that generics brings, at least where we make the calls.
The text was updated successfully, but these errors were encountered: