PC Review


Reply
Thread Tools Rate Thread

All methods are virtual?

 
 
Raymond Lewallen
Guest
Posts: n/a
 
      25th Aug 2004
I read this on this website page
http://www.vbip.com/books/1861004915...r_4915_06.asp:

Unlike many object-oriented languages, all methods in VB.NET are virtual.

Now in BOL, Under Perforamce Tips and Tricks in .NET Applications, A .Net
Developer Platform White Paper, at the very bottom, it says:

The JIT cannot inline virtual methods, so you lose a potential optimization
if you get rid of non-virtual methods.

So does this mean any method written in VB cannot be inlined, because they
are compiled as virtual? If so, whats the purpose of NotInheritable, or
NotOverridable?

If someone can point me to someplace that will help me on understanding this
discrepency, I would appreciate it. To this point, I've always understood
that VB.Net methods were not virtual if not declared explicitly as
Overridable, and could therefore have the possibility of being inlined.

Raymond Lewallen
Federal Aviation Administration


 
Reply With Quote
 
 
 
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      25th Aug 2004
Raymond Lewallen <(E-Mail Removed)> wrote:
> I read this on this website page
> http://www.vbip.com/books/1861004915...r_4915_06.asp:
>
> Unlike many object-oriented languages, all methods in VB.NET are virtual.


It's wrong - at least by what I consider the meaning of "virtual" to be
(namely that it can be overridden).

It even says earlier on that by default methods can't be overridden.

--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
 
Reply With Quote
 
One Handed Man \( OHM - Terry Burns \)
Guest
Posts: n/a
 
      25th Aug 2004
This is correct, methods must be explicitly marked 'Overridable'

Regards

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"Jon Skeet [C# MVP]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Raymond Lewallen <(E-Mail Removed)> wrote:
> > I read this on this website page
> > http://www.vbip.com/books/1861004915...r_4915_06.asp:
> >
> > Unlike many object-oriented languages, all methods in VB.NET are

virtual.
>
> It's wrong - at least by what I consider the meaning of "virtual" to be
> (namely that it can be overridden).
>
> It even says earlier on that by default methods can't be overridden.
>
> --
> Jon Skeet - <(E-Mail Removed)>
> http://www.pobox.com/~skeet
> If replying to the group, please do not mail me too



 
Reply With Quote
 
Raymond Lewallen
Guest
Posts: n/a
 
      25th Aug 2004
So am I correct in my assumption that by default, VB methods are NOT
virtual, which is how I've always understood it?


 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      25th Aug 2004
* "Raymond Lewallen" <(E-Mail Removed)> scripsit:
> So does this mean any method written in VB cannot be inlined, because they
> are compiled as virtual? If so, whats the purpose of NotInheritable, or
> NotOverridable?


'NotOverridable' is the default. You don't need to explicitly write it
in every method's head.

> If someone can point me to someplace that will help me on understanding this
> discrepency, I would appreciate it. To this point, I've always understood
> that VB.Net methods were not virtual if not declared explicitly as
> Overridable, and could therefore have the possibility of being inlined.


You are right -- the author of the text you mentioned is wrong.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
 
Reply With Quote
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      25th Aug 2004
Raymond Lewallen <(E-Mail Removed)> wrote:
> So am I correct in my assumption that by default, VB methods are NOT
> virtual, which is how I've always understood it?


Yup.

--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
 
Reply With Quote
 
cody
Guest
Posts: n/a
 
      25th Aug 2004
> * "Raymond Lewallen" <(E-Mail Removed)> scripsit:
> > So does this mean any method written in VB cannot be inlined, because

they
> > are compiled as virtual? If so, whats the purpose of NotInheritable, or
> > NotOverridable?

>
> 'NotOverridable' is the default. You don't need to explicitly write it
> in every method's head.


That is wrong. 'NotOverridable' means sealed in C# which is not the default
and must be written explicitly.
'NotOverridable' means a method cannot be overridden even if it is ifself a
virtual method.

--
cody

[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk


 
Reply With Quote
 
cody
Guest
Posts: n/a
 
      25th Aug 2004
> > Unlike many object-oriented languages, all methods in VB.NET are
virtual.
>
> It's wrong - at least by what I consider the meaning of "virtual" to be
> (namely that it can be overridden).


The author also claims that
" If all constructor methods of the base class require parameters then we
must implement at least one constructor in our subclass and we must
explicitly call MyBase.New from within our constructors. "

In my knowledge we must provide for each ctor of the baseclass a ctor of the
derived class which then calls the base class ctor.

--
cody

[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk


 
Reply With Quote
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      25th Aug 2004
cody <(E-Mail Removed)> wrote:
> > It's wrong - at least by what I consider the meaning of "virtual" to be
> > (namely that it can be overridden).

>
> The author also claims that
> " If all constructor methods of the base class require parameters then we
> must implement at least one constructor in our subclass and we must
> explicitly call MyBase.New from within our constructors. "


That's true, I believe. Can you give a counter-example? For instance,
can you provide a class with no constructor specified but which derives
from:

public class Foo
{
public Foo (int i)
{
}
}

?

> In my knowledge we must provide for each ctor of the baseclass a ctor of the
> derived class which then calls the base class ctor.


Not at all. Every constructor in the derived class must call a base
class constructor, but there's nothing to say that you *have* to have
as many derived class constructors as there are base class
constructors.

--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
 
Reply With Quote
 
Raymond Lewallen
Guest
Posts: n/a
 
      26th Aug 2004
Cody,

My original post concerned VB, which is what Herfried was referring to, and
he was correct in his post. In VB, NotOverridable is the default. I'm not
sure about C#, as I do 90% of my programming in VB.

Raymond Lewallen
Federal Aviation Administration

"cody" <(E-Mail Removed)> wrote in message
news:u2$(E-Mail Removed)...
> > * "Raymond Lewallen" <(E-Mail Removed)> scripsit:
> > > So does this mean any method written in VB cannot be inlined, because

> they
> > > are compiled as virtual? If so, whats the purpose of NotInheritable,

or
> > > NotOverridable?

> >
> > 'NotOverridable' is the default. You don't need to explicitly write it
> > in every method's head.

>
> That is wrong. 'NotOverridable' means sealed in C# which is not the

default
> and must be written explicitly.
> 'NotOverridable' means a method cannot be overridden even if it is ifself

a
> virtual method.
>
> --
> cody
>
> [Freeware, Games and Humor]
> www.deutronium.de.vu || www.deutronium.tk
>
>



 
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
need interface methods to be virtual-able =?Utf-8?B?QmVubnk=?= Microsoft Dot NET 9 17th Jul 2006 10:32 AM
All methods are virtual? Raymond Lewallen Microsoft Dot NET 20 26th Aug 2004 10:34 PM
interface methods always virtual? Fuzzy Microsoft C# .NET 1 25th Feb 2004 12:59 PM
virtual methods Mark Microsoft C# .NET 1 23rd Jan 2004 07:51 PM
Non-virtual methods - why? Adrian Herscu Microsoft C# .NET 30 29th Sep 2003 10:37 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:02 AM.