Replies: 6 comments 29 replies
-
Will the indexer for list pattern require Also you mentioned that not much time left to freeze c# 10 feature set and i would like to ask status on |
Beta Was this translation helpful? Give feedback.
-
If
|
Beta Was this translation helpful? Give feedback.
-
Did you consider my suggestion to always use square brackets AND curly braces for list patterns?
|
Beta Was this translation helpful? Give feedback.
-
What about putting length after |
Beta Was this translation helpful? Give feedback.
-
Going off at a tangent to the topic of this thread, but is it documented anywhere how having a preview feature (static abstracts in interfaces) in the release of C# 10 will work? Thanks. |
Beta Was this translation helpful? Give feedback.
-
This was cleared up in Discord but I got the impression reading these notes that the decision was to keep to the square brackets denoting a length pattern and the curly brackets denoting the items. I think a quick example highlighting the syntax and behavior of the "original" proposal might have helped to clarify the options and the result of the decision. To make sure that I'm still not wrong I'll post some syntax and my interpretations of that syntax and you can let me know how off-base I am: // given
List<string> list = new List<string>() { "foo", "bar", "baz" };
int[] array = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
// collection contains exactly specific items
Debug.Assert(list is ["foo", "bar", "baz"]);
// collection starts with specific items
Debug.Assert(list is ["foo", .. ]);
// collection has at least one item and extract the last item into a variable pattern
Debug.Assert(list is [ .., var temp1] && temp1 == "baz");
// collection has a specific length and first/last items
Debug.Assert(list is { Count: 3 } and ["foo", .., "baz"]);
// array starts with specific items
Debug.Assert(array is [1, 2, .. ]);
// array has a minimum length and extract the last item into a variable pattern
Debug.Assert(array is { Length: >5 } and [.., var last] && last == 10);
object o = array;
// object is an int array and starts/ends with specific items
Debug.Assert(o is int[] and [1 , .., 10]); |
Beta Was this translation helpful? Give feedback.
-
https://github.com/dotnet/csharplang/blob/main/meetings/2021/LDM-2021-06-14.md
Agenda
Beta Was this translation helpful? Give feedback.
All reactions