473,614 Members | 2,508 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 2292
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
1587
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
1852
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
3151
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
2388
by: ypjofficial | last post by:
Hello All, I have following doubt.. class abstractclass { public: abstractclass(){} virtual void method()=0; };
6
1939
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
2642
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
3076
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 implamentation files together. The base class header is #ifndef _BASEDATA_H_ #define _BASEDATA_H_ ...
12
4801
by: Robert Fuchs | last post by:
Hello, This example: public class BaseC { public int x; public void Invoke() {} } public class DerivedC : BaseC
0
8198
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8591
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8294
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7115
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6093
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4138
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2575
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1758
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1438
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.