Practice mode C#

Which keyword is used to declare an indexer in a C# class?

Correct answer A. this

Explanation

An indexer is declared like a property whose name is this followed by parameters in square brackets: public int this[int i] { get => data[i]; set => data[i] = value; }. Objects can then be accessed with array syntax such as obj[2]. Indexers can be overloaded with different parameter types, for example a string key. Item is the name the compiler emits internally.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.