note the return types of index and range operations#16290
note the return types of index and range operations#16290BillWagner merged 4 commits intodotnet:masterfrom
Conversation
Provide a brief description of the return types for index and range expressions.
| If a type provides an [indexer](../programming-guide/indexers/index.md) with an <xref:System.Index> or <xref:System.Range> parameter, it explicitly supports indices or ranges respectively. In these cases, the index or range expression returns the type returned by that indexer. | ||
|
|
||
| A type is **countable** if it has a property named `Length` or `Count` with an accessible getter and a return type of `int`. A countable type that doesn't explicitly support indices or ranges may provide an implicit support for them. For more information, see the [Implicit Index support](~/_csharplang/proposals/csharp-8.0/ranges.md#implicit-index-support) and [Implicit Range support](~/_csharplang/proposals/csharp-8.0/ranges.md#implicit-range-support) sections of the [feature proposal note](~/_csharplang/proposals/csharp-8.0/ranges.md). | ||
| A type is **countable** if it has a property named `Length` or `Count` with an accessible getter and a return type of `int`. A countable type that doesn't explicitly support indices or ranges may provide an implicit support for them. For more information, see the [Implicit Index support](~/_csharplang/proposals/csharp-8.0/ranges.md#implicit-index-support) and [Implicit Range support](~/_csharplang/proposals/csharp-8.0/ranges.md#implicit-range-support) sections of the [feature proposal note](~/_csharplang/proposals/csharp-8.0/ranges.md). An implicit index operator returns the same type as the indexer that takes a single `int` parameter. Range expressions typically return the same type as the left operand of the range expression. |
There was a problem hiding this comment.
An implicit index operator returns the same type as the indexer that takes a single
intparameter.
That might be difficult to process if the links to the spec are not followed. The preceding text in the paragraph doesn't mention the indexer with a single int parameter. I think that sentence can be removed at all. It's almost obvious that index expression has the type of sequence element. The linked issue is about the range expression.
The range expression is not defined. It can be an expression of the form a..b, but I think it's the wrong guess for this paragraph. Most probably, it's s[a..b] then. However, in both cases I would use the "left operand" to refer to a. Can we refer to s as the "source sequence" like in the following suggestion:
| A type is **countable** if it has a property named `Length` or `Count` with an accessible getter and a return type of `int`. A countable type that doesn't explicitly support indices or ranges may provide an implicit support for them. For more information, see the [Implicit Index support](~/_csharplang/proposals/csharp-8.0/ranges.md#implicit-index-support) and [Implicit Range support](~/_csharplang/proposals/csharp-8.0/ranges.md#implicit-range-support) sections of the [feature proposal note](~/_csharplang/proposals/csharp-8.0/ranges.md). An implicit index operator returns the same type as the indexer that takes a single `int` parameter. Range expressions typically return the same type as the left operand of the range expression. | |
| A type is **countable** if it has a property named `Length` or `Count` with an accessible getter and a return type of `int`. A countable type that doesn't explicitly support indices or ranges may provide an implicit support for them. For more information, see the [Implicit Index support](~/_csharplang/proposals/csharp-8.0/ranges.md#implicit-index-support) and [Implicit Range support](~/_csharplang/proposals/csharp-8.0/ranges.md#implicit-range-support) sections of the [feature proposal note](~/_csharplang/proposals/csharp-8.0/ranges.md). An implicit index operator returns the same type as the indexer that takes a single `int` parameter. Range expressions typically return a sequence of the same type as the type of the source sequence. |
There was a problem hiding this comment.
I took your suggestion. I think I should do more here. Another edit round coming soon.
There was a problem hiding this comment.
@pkulikov Let me know what you think of this update.
There was a problem hiding this comment.
@BillWagner LGTM modulo two suggestions, one of which fixes the xref link.
Co-Authored-By: Petr Kulikov <petr.kulikov@gmail.com>
Co-Authored-By: Petr Kulikov <petr.kulikov@gmail.com>
Provide a brief description of the return types for index and range expressions.
Fixes #15067 (leveraging the changes in dotnet/samples#1620