dotnet / docs

This repository contains .NET Documentation.
https://learn.microsoft.com/dotnet
Creative Commons Attribution 4.0 International
4.18k stars 5.85k forks source link

"Using Indexers - C# Programming Guide" should mention `ref returns` #31360

Closed TymurGubayev closed 1 year ago

TymurGubayev commented 1 year ago

Following statement isn't quite correct.

An indexer value is not classified as a variable; therefore, you cannot pass an indexer value as a ref or out parameter.

But you can pass an indexer value as a ref, if the indexer uses ref return, like this.

        private readonly int[] arr = new int[10];
        public ref int this[int index]
        {
            get
            {
                return ref arr[index];
            }
        }

Document Details

Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.

BillWagner commented 1 year ago

Thanks for spotting this. We'll get this updated.