473,573 Members | 2,733 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

All methods are virtual?

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
Nov 21 '05 #1
20 5526
Raymond Lewallen <Ra************ ******@nospam.f aa.gov> 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 - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 21 '05 #2
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]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Raymond Lewallen <Ra************ ******@nospam.f aa.gov> 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 - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 21 '05 #3
So am I correct in my assumption that by default, VB methods are NOT
virtual, which is how I've always understood it?
Nov 21 '05 #4
Raymond Lewallen <Ra************ ******@nospam.f aa.gov> 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 - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 21 '05 #5
* "Raymond Lewallen" <Ra************ ******@nospam.f aa.gov> 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/>
Nov 21 '05 #6
> * "Raymond Lewallen" <Ra************ ******@nospam.f aa.gov> 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
Nov 21 '05 #7
> > 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
Nov 21 '05 #8
cody <pl************ *************@g mx.de> 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 - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 21 '05 #9
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" <pl************ *************@g mx.de> wrote in message
news:u2******** ******@tk2msftn gp13.phx.gbl...
* "Raymond Lewallen" <Ra************ ******@nospam.f aa.gov> 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

Nov 21 '05 #10

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

Similar topics

20
1758
by: Raymond Lewallen | last post by:
I read this on this website page http://www.vbip.com/books/1861004915/chapter_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,...
32
4489
by: Adrian Herscu | last post by:
Hi all, In which circumstances it is appropriate to declare methods as non-virtual? Thanx, Adrian.
3
6640
by: Danny Din | last post by:
Hi, I have the following code – public class Class1 { public Class1()
175
8754
by: Ken Brady | last post by:
I'm on a team building some class libraries to be used by many other projects. Some members of our team insist that "All public methods should be virtual" just in case "anything needs to be changed". This is very much against my instincts. Can anyone offer some solid design guidelines for me? Thanks in advance....
4
2339
by: Stefan Nikolaus | last post by:
Hello, I've run into problems with defining a template, which inherits from a base template and the usage of virtual methods in those. I want to initialize a member variable depending on which template is created and I tried to define a virtual method, that's called from the base template ctor. Here's my example code: #include...
318
10862
by: King Raz | last post by:
The shootout site has benchmarks comparing different languages. It includes C# Mono vs Java but not C# .NET vs Java. So I went through all the benchmark on the site ... http://kingrazi.blogspot.com/2008/05/shootout-c-net-vs-java-benchmarks.html Just to keep the post on topic for my friends at comp.lang.c++, how do I play default windows...
2
1771
by: fgh.vbn.rty | last post by:
Hi, I'm not sure if i'm asking the question correctly but anyway here it is. Say I have 3 classes - class A, class B, class R. 1) A and B are the building blocks and R is like a repository that stores objects of A and B. 2) A is at the lowest level and should "know about" only other As. B should know only about As and other Bs.
0
7784
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...
0
7705
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8033
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8077
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5601
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...
0
5294
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3734
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1316
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1044
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...

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.