Back to Csharplang

C# Language Design Meeting for April 14th, 2025

meetings/2025/LDM-2025-04-14.md

latest3.2 KB
Original Source

C# Language Design Meeting for April 14th, 2025

Agenda

Discussion

Dictionary expressions

Champion issue: https://github.com/dotnet/csharplang/issues/8887
Specification: https://github.com/dotnet/csharplang/blob/e2e62a49d32f0d659b8baf0f23ee211b69563c65/proposals/dictionary-expressions.md#open-questions

Parsing ambiguity

Should [a ? [b] : c] be parsed as [a ? ([b]) : (c)] or [(a?[b]) : c]?

Conclusion

Parse as [a ? ([b]) : (c)]. If the user intends to use the conditional operator, they can use parentheses and [(a?[b]) : c].

Implement non-generic IDictionary when targeting IReadOnlyDictionary<,>

The existing types we might use to implement IReadOnlyDictionary implement IDictionary and implementing the interface on future types is not onerous.

Conclusion

The type used when target typing IReadOnlyDictionary<,> should implement IDictionary.

Collection expression arguments

Champion issue: https://github.com/dotnet/csharplang/issues/8887
Specification: https://github.com/dotnet/csharplang/blob/e2e62a49d32f0d659b8baf0f23ee211b69563c65/proposals/collection-expression-arguments.md#open-questions

Target types where arguments are required

Types that require at least one argument in all constructors and factory methods can't be used for params collections. We discussed whether conversions should be supported for collection expressions for these types.

We also discussed whether to require the presence of with to allow these conversions.

Conclusion

Yes, conversions will be supported. Yes, require with to allow these conversions.

Arguments for interface types

For concrete types, we support the arguments available on constructors or factory methods.

But, should we support arguments for interface target types, and if so, what method signatures should be used binding the arguments.

Using the available constructors may result in signatures that are not particularly helpful. For example, when including a collection in a collection expression, a spread operator seems more clear than a with parameter. And depending on the types involved, what's allowed may be unexpected:

csharp
List<int> list1  = [with(otherList)]; // allowed.
IList<int> list2 = [with(otherList)]; // not allowed.
IList<int> list3 = (List<int>)[with(otherList)]; // allowed.

There are a small number of constructor args that are very useful in collection expressions, such as:

  • Capacity and comparer for mutable (the capacity might change)
  • Comparer only for immutable (we know the capacity)

Now that we understand the implications of a generalized solution for comparer and capacity, we are less certain that the generalized solution is the correct approach - so we will reconsider this. The team will explore what arguments are useful and return with a curated list and recommendation. We can add support for additional arguments as use cases arise.

__arglist

We see very little value in supporting __arglist in collection expression arguments.

Conclusion

We will not support __arglist unless they are "free" to support.