[CSHARP-4076] Support index from end (^) operator Created: 24/Feb/22 Updated: 24/Feb/22 Resolved: 24/Feb/22 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | LINQ3 |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | New Feature | Priority: | Unknown |
| Reporter: | James Kovacs | Assignee: | James Kovacs |
| Resolution: | Won't Do | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
C# 8 introduced new syntax to index from the end of an array:
The C# compiler translates ^ into an Index object. We would need to support new overloads for array access, IEnumerable.ElementAt(Index), and related methods. More details on the C#8 syntax can be found here: |
| Comments |
| Comment by James Kovacs [ 24/Feb/22 ] | ||
|
Turns out the C# compiler does not permit the Index and Range operators in expression trees. Including x.SomeArray[^1] or x.SomeArray[1..^1] in a LINQ expression results in the following compiler errors. The same errors occur if you assign the expression to Expression<T>. Unfortunately this syntax is not permitted even using C# 10 and .NET 6.
|