Click here to Skip to main content
15,074,181 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
Updated 2-Oct-12 19:41pm
v2

1 solution

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)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900