473,573 Members | 2,883 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2291
Clive,

Have you tried using:

return base[o];

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

"Clive Dixon" <cl************ *******@digita. noluncheonmeat. com> wrote in
message news:eP******** ******@TK2MSFTN GP12.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.c om> wrote in
message news:uD******** ******@TK2MSFTN GP12.phx.gbl...
Clive,

Have you tried using:

return base[o];

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

"Clive Dixon" <cl************ *******@digita. noluncheonmeat. com> wrote in
message news:eP******** ******@TK2MSFTN GP12.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*******@hotm ail.com> wrote in news:1135014083 .889257.105890
@g44g2000cwa.go oglegroups.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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1635
by: Iulian Ionescu | last post by:
I have the following problem. I derived a class from ArrayList to provide some additional events I need. Then I derived 2 different classes from this one and each of them defines an indexer that returns the specified object. For example, the list for Group types will have: public new Group this { get {return (Group)base;}
3
1585
by: hazz | last post by:
The following classes follow from the base class ' A ' down to the derived class ' D ' at the bottom of the inheritance chain. I am calling the class at the bottom, "public class D" from a client app with; D m_D = new D(tkn); public class A : MarshalByRefObject public A () <--------------------- public class B : A public B ()...
5
1851
by: SpotNet | last post by:
Hello NewsGroup, I have a custom class and a collection for that custom class that inherits CollectionBase. As such; public class MyClass { private string datamember1 = string.Empty, datamember2 = string.Empty; private int datamember3 = -1;
5
3148
by: Andy | last post by:
Hi all, I have a site with the following architecture: Common.Web.dll - Contains a CommonPageBase class which inherits System.Web.UI.Page myadd.dll - Contains PageBase which inherits CommonPageBase - Contains myPage which inherits PageBase Each of these classes overrides OnInit and ties an event handler
22
2381
by: ypjofficial | last post by:
Hello All, I have following doubt.. class abstractclass { public: abstractclass(){} virtual void method()=0; };
6
1938
by: Ole Nielsby | last post by:
I'm having a strange problem with sealing virtual indexers. Looks like a compiler error to me - or have I overlooked some obscure statement in the specs? I have two virtual indexers in the same class, one of them by string, the other by int. The weird thing is, if I seal one of them, I can't override the other. Here is the code.
9
2637
by: J055 | last post by:
Hi I have a standard asp page which uses a MasterPage. The MasterPage contains a User control. How can I access a public method in the User control from my WebForm page? I can't move the method to another location because it populates a Textbox in the user control page. Thanks Andrew
3
3071
by: djsuson | last post by:
I'm trying to set up an inheritance tree that also uses templates. This is an attempt to simplify some previous code that was filled with redundancies. I'm working with g++ 3.4.6. The code is split over four files: two headers and two implamentation files, but uses the include trick mentioned on another thread to connect the header and...
12
4792
by: Robert Fuchs | last post by:
Hello, This example: public class BaseC { public int x; public void Invoke() {} } public class DerivedC : BaseC
0
7784
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7705
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8205
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
5601
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5294
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3734
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3739
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1310
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1044
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.