Can we use static notation in indexers in C#?

 Posted by CGN007 on 5/30/2012 | Category: C# Interview questions | Views: 2447 | Points: 40
Answer:

No.We can't use static notation in indexers.
Consider the indexer syntax

 public int this[int index]

{
get {
// return the value specified by index
}

set {
// set the value specified by index
}
}

Here we can see that indexer uses a reference to
this
,Which is not supported by static.The reason behind this is static does not support,instance of a class,so we cant use
 this 
reference.
Hence We can't use static notation in indexers.


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response