PC Review


Reply
Thread Tools Rate Thread

Call ovverided method base of base

 
 
smrah1@gmail.com
Guest
Posts: n/a
 
      22nd Oct 2008

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
 
Reply With Quote
 
 
 
 
Brian
Guest
Posts: n/a
 
      22nd Oct 2008
In class C you could probably do this (although I haven't tested):

((A)base).Write();

"(E-Mail Removed)" 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
>

 
Reply With Quote
 
smrah1@gmail.com
Guest
Posts: n/a
 
      24th Oct 2008

> ((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
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to call base implementation of method from base John Rivers Microsoft C# .NET 2 17th Oct 2010 03:51 PM
how to make sure this.Test() call base class method in base class constructor Ryan Liu Microsoft C# .NET 2 27th Aug 2006 07:43 PM
Call to base method Janaka Microsoft C# .NET 3 24th Sep 2004 03:20 PM
How to use the base keyword to call a base class method (not a constructor) Bob Rock Microsoft C# .NET 1 26th Aug 2003 01:27 PM
How to call a base class's base class method Bill Menees Microsoft C# .NET 1 23rd Jul 2003 02:17 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:06 PM.