473,326 Members | 2,337 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Call ovverided method base of base


Hi

we have like below code:

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
A a = new C();
a.Write();
}
}

class A
{
public virtual void Write()
{
Console.WriteLine("Class A");
}
}

class B : A
{
public override void Write()
{
Console.WriteLine("Class B");
}
}

class C : B
{
public override void Write()
{
Console.WriteLine("Class C");
base.Write();
}
}
}

When run ,outout is:

Class C
Class B

Now I want change below line of class C:

base.Write();

that output will like :

Class C
Class A

in Other words,change overrided method of class C that no run method
of base (class B) but run this method on - class A (base of base of
class C).

thanks
SMRAH1
Oct 22 '08 #1
4 1644
In class C you could probably do this (although I haven't tested):

((A)base).Write();

"sm****@gmail.com" wrote:
>
Hi

we have like below code:

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
A a = new C();
a.Write();
}
}

class A
{
public virtual void Write()
{
Console.WriteLine("Class A");
}
}

class B : A
{
public override void Write()
{
Console.WriteLine("Class B");
}
}

class C : B
{
public override void Write()
{
Console.WriteLine("Class C");
base.Write();
}
}
}

When run ,outout is:

Class C
Class B

Now I want change below line of class C:

base.Write();

that output will like :

Class C
Class A

in Other words,change overrided method of class C that no run method
of base (class B) but run this method on - class A (base of base of
class C).

thanks
SMRAH1
Oct 22 '08 #2
On Wed, 22 Oct 2008 11:59:00 -0700, <sm****@gmail.comwrote:
[...]
in Other words,change overrided method of class C that no run method
of base (class B) but run this method on - class A (base of base of
class C).
How is this different from the question to which I already replied?
Oct 22 '08 #3
((A)base).Write();
Error
How is this different from the question to which I already replied?
I dont find!
I dont know!
Please repeat!Please!

Sincerely
Oct 24 '08 #4
On Fri, 24 Oct 2008 00:48:57 -0700, <sm****@gmail.comwrote:
>((A)base).Write();

Error
>How is this different from the question to which I already replied?

I dont find!
I dont know!
Please repeat!Please!
It appears that once again, Google Groups has dropped a user's thread
(that is, yours).

Why people tolerate Google Groups as a newsgroup portal, I have no idea.
I haven't ever seen such lack of reliability, _ever_. And I've used a lot
of different news providers over the years.

Anyway, when your thread goes missing in Google Groups, the first thing
you should do before reposting is looking at the other Usenet archives to
see if you can find the thread there. Putting the subject for your
previous thread into Google's web search ("run virtual method in inherit
class") turns up a number of other sites that _did_ archive the thread and
which include my reply.

Here's the first such search result:
http://bytes.com/forum/thread847491.html

If you insist on continuing to use Google Groups to read and post to
newsgroups, get used to doing that on a regular basis.

Pete
Oct 24 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Daniel Kay | last post by:
Hello! I have written two template classes which implement the observerpattern in C++. I hope I manage to desribe the problem I have. template<class T> class Observer { /* ... */ }; ...
4
by: Amy Matlock | last post by:
Hi all: How does the hardware work if you invoke a BASE::METHOD() on a DERIVED class member? Do you still hit the v-table dynamically at run time? Suppose you have a derived class method, but...
9
by: keith | last post by:
I created a class libery which has name space Assembly and class Assembly and compiled it. Then created a C# project and called a method in the external class e.g. Assembly dll;...
15
by: jon | last post by:
How can I call a base interface method? class ThirdPartyClass :IDisposable { //I can not modify this class void IDisposable.Dispose() { Console.WriteLine( "ThirdPartyClass Dispose" ); } } ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.