471,306 Members | 1,226 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,306 software developers and data experts.

Accessing indexer of base class with identical signature

Is it possible to access an indexer of a base class with identical
signature, e.g.

class Class1
{
public object this[object o]
{
get
{
// ...
}
}
}

class Class2 : Class1
{
public new object this[object o]
{
get
{
return base.this[o];
}
}
}

The compiler will not accept 'base.this' nor 'base.Item'/'base.get_Item' and
I can't find any reference to calling base class indexers anywhere in the
documentation. Now if the base class indexer has a different signature I can
simply use 'this' rather than 'base.this' and cast the indexer parameter to
that of the base class's indexer to force calling the correct base class
indexer, but if the signatures are identical I cannot see how to call the
base class indexer.
Dec 19 '05 #1
5 2147
Clive,

Have you tried using:

return base[o];

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Clive Dixon" <cl*******************@digita.noluncheonmeat.com > wrote in
message news:eP**************@TK2MSFTNGP12.phx.gbl...
Is it possible to access an indexer of a base class with identical
signature, e.g.

class Class1
{
public object this[object o]
{
get
{
// ...
}
}
}

class Class2 : Class1
{
public new object this[object o]
{
get
{
return base.this[o];
}
}
}

The compiler will not accept 'base.this' nor 'base.Item'/'base.get_Item'
and I can't find any reference to calling base class indexers anywhere in
the documentation. Now if the base class indexer has a different signature
I can simply use 'this' rather than 'base.this' and cast the indexer
parameter to that of the base class's indexer to force calling the correct
base class indexer, but if the signatures are identical I cannot see how
to call the base class indexer.

Dec 19 '05 #2

Clive Dixon wrote:
Is it possible to access an indexer of a base class with identical
signature, e.g.

class Class1
{
public object this[object o]
If your method really is called 'this' then I can't even begin to
imagine what the compiler thinks you mean!
class Class2 : Class1
{
public new object this[object o]


Why 'new' when nothing has changed?

--
Larry Lard
Replies to group please

Dec 19 '05 #3

Larry Lard wrote:
[snip]
class Class2 : Class1
{
public new object this[object o]
Why 'new' when nothing has changed?


Sorry, brainfart, please ignore. My previous comment stands though.

--
Larry Lard
Replies to group please


Dec 19 '05 #4
Yep thanks Nicholas. Obvious once pointed out, but I just didn't spot it.

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:uD**************@TK2MSFTNGP12.phx.gbl...
Clive,

Have you tried using:

return base[o];

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Clive Dixon" <cl*******************@digita.noluncheonmeat.com > wrote in
message news:eP**************@TK2MSFTNGP12.phx.gbl...
Is it possible to access an indexer of a base class with identical
signature, e.g.

class Class1
{
public object this[object o]
{
get
{
// ...
}
}
}

class Class2 : Class1
{
public new object this[object o]
{
get
{
return base.this[o];
}
}
}

The compiler will not accept 'base.this' nor 'base.Item'/'base.get_Item'
and I can't find any reference to calling base class indexers anywhere in
the documentation. Now if the base class indexer has a different
signature I can simply use 'this' rather than 'base.this' and cast the
indexer parameter to that of the base class's indexer to force calling
the correct base class indexer, but if the signatures are identical I
cannot see how to call the base class indexer.


Dec 19 '05 #5
"Larry Lard" <la*******@hotmail.com> wrote in news:1135014083.889257.105890
@g44g2000cwa.googlegroups.com:
If your method really is called 'this' then I can't even begin to
imagine what the compiler thinks you mean!


It's called an indexer...

Reference: http://msdn.microsoft.com/library/de...l=/library/en-
us/csspec/html/vclrfcsharpspec_10_8.asp

(watch the wrap)

-mdb
Dec 19 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Iulian Ionescu | last post: by
5 posts views Thread by SpotNet | last post: by
5 posts views Thread by Andy | last post: by
6 posts views Thread by Ole Nielsby | last post: by
9 posts views Thread by J055 | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.