PC Review


Reply
Thread Tools Rate Thread

how to make sure this.Test() call base class method in base class constructor

 
 
Ryan Liu
Guest
Posts: n/a
 
      27th Aug 2006
Hi,

There is a method Test() implemented in base class and override in subclass.

In base class itself, how to make sure

this.Test() will just call implementation in base class only?

Thanks a lot!
Ryan Liu


 
Reply With Quote
 
 
 
 
Mattias Sjögren
Guest
Posts: n/a
 
      27th Aug 2006
Ryan,

>In base class itself, how to make sure
>
>this.Test() will just call implementation in base class only?


You can't, that would defeat the purpose of virtual methods. Instead
you can move the base class' implementation of the Test method to
another, not-virtual method (say TestImpl). Call TestImpl from from
Test and call TestImpl directly if you want non-virtual behaviour.


Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
 
Reply With Quote
 
 
 
 
=?ISO-8859-1?Q?Arne_Vajh=F8j?=
Guest
Posts: n/a
 
      27th Aug 2006
Ryan Liu wrote:
> There is a method Test() implemented in base class and override in subclass.
>
> In base class itself, how to make sure
>
> this.Test() will just call implementation in base class only?


You can not force an implementation in a subclass.

But you can omit the virtual keyword, so they can not
override.

Arne
 
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
Derived class Interface method needs to call Base Class Interface Method Kevin Frey Microsoft C# .NET 2 1st Dec 2006 07:57 PM
can I call from one constructor another constructor ? Paul Microsoft Dot NET Framework 24 14th Jul 2004 02:29 PM
Can I call another constructor from a constructor? Tom Microsoft C# .NET 3 21st Apr 2004 04:46 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 02:38 AM.