Allow KeyValuePair<string, string>[] array = new[] { new("key1", value1), new("key2", value2) };
With introduction of new()
expression (#100), the following:
IEnumerable<KeyValuePair<string, string>> Headers = new[] { new KeyValuePair<string, string>("Foo", foo), new KeyValuePair<string, string>("Bar", bar), }
can be simplified to:
IEnumerable<KeyValuePair<string, string>> Headers = new KeyValuePair<string, string>[] { new("Foo", foo), new("Bar", bar), }
but you still need to repeat the type following the field/property initializer. Closest you can get is something like:
IEnumerable<KeyValuePair<string, string>> Headers = new[] { new KeyValuePair<string, string>("Foo", foo), new("Bar", bar), }
For the sake of completeness, I'd suggest to also make new[]
a target-typed expression,
IEnumerable<KeyValuePair<string, string>> Headers = new[] { new("Foo", foo), new("Bar", bar), }
The mechanics of such feature is similar to #2389 or #2460 where there are two source of type inference, the common type and the target-type.
Note: A list/dictionary literal feature would not supersede this proposal because in above examples there's no concrete collection type to infer.
YairHalberstadt, orthoxerox, mattwar, rubenprins, iam3yal and 58 moreUnknown6656, tuscen and MadProbeMteheran, ChristopherHaws, mateusdemboski, FaustVX, tuscen and 3 more
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4