user2071747
user2071747

Reputation: 201

C# recursion in 'new' method

I have this code in my class MyClass:

public new MyClass this[int index]
    {
        get
        {
            if (Count > index)
            {
                return this[index];
            }
            //...MyActions...
            return null;
        }
    }

In string...

return this[index]

... i have recursion, but i need use properties in base class. I dont know how do it.

Example:

 return base.this[index]

But i dont may 'override' this method, only set 'new'. I sad

How do it? Sorry my very bad english and thanks

Upvotes: 3

Views: 132

Answers (2)

Grant Thomas
Grant Thomas

Reputation: 45083

Then use base as desired:

return base[index];

For example:

public class A {
  public object this[int index] { get; }
}

public class B : A {
  public object this[int index] {
    get { return base[index]; }
  }
}

Upvotes: 3

Ilya Ivanov
Ilya Ivanov

Reputation: 23626

You can use base keyword to access members of the base class including indexers. Try to use next code snippet to call indexer on base class:

return base[index];

Upvotes: 5

Related Questions