4 ms·
You could create tuples with `Tuple.Create("a", 1)` since at least .NET 4, if not 3. Since C# 7 you can also create tuples using just `("a", 1)`. But tuples ar
by gnud 6y ago
You could create tuples with `Tuple.Create("a", 1)` since at least .NET 4, if not 3.
Since C# 7 you can also create tuples using just `("a", 1)`. But tuples are not KeyValuePairs. So the new "new" syntax will be very helpful in a lot of cases.
- DaiPlusPlus 6y agoI really don't understand why they haven't added implicit conversion operators between the modern ValueTuple and the legacy value-types like KeyValuePair, Tuple, and Pair, grumble. It's a non-breaking change!
- jsmith45 6y agoAdding that is potentially a source breaking change. Admittedly an easy enough one to address, and they are more willing to make such changes in CoreFx, then they historically were, so it is not impossible that they could decide to do it. For an example of this being a breaking change. Let's say that B is some other type implicitly convertable to A. The following two method overloads exists: void Method(A a, ValueTuple<int,int> vt); void Method(B b, Tuple<int, int> t); Right now `Method(SomeB, (4,5))` compiles fine, but if your proposed conversions were added, it would suddenly yield `CS0121: The call is ambiguous between the following methods or properties:...`.
- ygra 6y agoTuple is not a value type. And this means that they won't add an implicit conversion, because right now a major focus of .NET and C# is also performance. and this conversion would mean an implicit heap allocation. They'd rather avoid adding features of this sort as I understand it.