Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#3.0 C#4.0
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
Edited 2-Oct-12 19:41pm
Mehdi Gholam237.4K
v2

1 solution

Rate this: bad
good
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!
  Permalink  

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

  Print Answers RSS
0 Dnyaneshwar@Pune 604
1 thatraja 370
2 OriginalGriff 319
3 Sergey Alexandrovich Kryukov 243
4 Gihan Liyanage 194
0 OriginalGriff 737
1 Dnyaneshwar@Pune 604
2 Kornfeld Eliyahu Peter 505
3 Sergey Alexandrovich Kryukov 372
4 thatraja 370


Advertise | Privacy | Mobile
Web02 | 2.8.140902.1 | Last Updated 3 Oct 2012
Copyright © CodeProject, 1999-2014
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