Skip to content
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

Omit Type for Generic Initialization #25527

Closed
szaliubovskii opened this issue Mar 16, 2018 · 2 comments
Closed

Omit Type for Generic Initialization #25527

szaliubovskii opened this issue Mar 16, 2018 · 2 comments

Comments

@szaliubovskii
Copy link

We can initialize generics with initial data, but we still have to specify type of the generic. It would be nice to omit type defenition in that case.

Currently following statements are legal.

int[] array = { 1, 2, 3 };
var array = new[] { 1, 2, 3 };
var list = new List<int> { 1, 2, 3 };
var dictionary = new Dictionary<string, string> { ["key"] = "value" };

With syntax proposed in this topic you'd be able to write:

var list = new List { 1, 2, 3 };           // List<int>
var dictionary = new Dictionary { ["key"] = "value" }; // Dictionary<string,string>

It is simmilar to how type omit works for Generic Methods.

...
public static T GetData<T>(T data) => data;
...

// type is omited in this case
var data = GetData(1);

Relates to #5865 issue.

@Neme12
Copy link
Contributor

Neme12 commented Mar 16, 2018

belongs to https://github.com/dotnet/csharplang/, please move this

@szaliubovskii
Copy link
Author

Sure, will open there and colse this one. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants