Click here to Skip to main content
13,085,936 members (88,037 online)
Rate this:
Please Sign up or sign in to vote.
See more:
There are two important restrictions to using indexers. First,because an indexer does
not define a storage location, a value produced by an indexer cannot be passed as a ref or
out parameter to a method. Second, an indexer must be an instance member of its class; it
cannot be declared static.

1. why we can't pass produced value by indexer as ref or out parameter to an method?

2. why indexers can not be static?
Posted 2-Oct-12 19:37pm
Updated 2-Oct-12 19:41pm
Mehdi Gholam341.1K

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Your quote answers your first question pretty exactly:
1) "because an indexer does not define a storage location"

It doesn't produce any storage related value so you can't pint a reference at it. If it doesn't have a value that a reference can point at, it can't be a reference, so it can't be passed as a reference. An Indexer is not a number: it is a process in a stage of execution.

2) Because it is an indexer into a specific instance of the class - if it was static, it would be a global indexer for all instances, and that would be silly - if you have two lists which of them should a global indexer return a value from? What if they have a different number of elements? Indexers have to be related to the specific indexable instance, or they can't work!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.170813.1 | Last Updated 3 Oct 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100