473,327 Members | 1,892 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,327 software developers and data experts.

Class member initial values.

Hello,

question about following code:

Class MariaBello
Private intCount As Integer = 0
Private objLauraLinney As New LauraLinney()
End Class

Class TylerDurden
Private intCount As Integer
Private objLauraLinney As LauraLinney
Public Sub New()
intCount = 0
objLauraLinney = New LauraLinney()
End Sub
End Class

Is there any difference between the 2 methods of giving intCount its value?
Exceptions may occure when creating a new object, so you could catch them
inside New(), but other than that, what is the prefered method of creating
the new object and why?

Thanks.

Nov 21 '05 #1
2 969
Qwert,

My prefered methods are those, which shows in the shortest way to another
one, (who is reading the program afterwards) (and myself too) what I did.

Just my thought,

Cor
Nov 21 '05 #2
"Qwert" <no**@nosp.com> schrieb:
Class MariaBello
Private intCount As Integer = 0
Private objLauraLinney As New LauraLinney()
End Class

Class TylerDurden
Private intCount As Integer
Private objLauraLinney As LauraLinney
Public Sub New()
intCount = 0
objLauraLinney = New LauraLinney()
End Sub
End Class

Is there any difference between the 2 methods of giving intCount its
value? Exceptions may occure when creating a new object, so you could
catch them inside New(), but other than that, what is the prefered method
of creating the new object and why?


I suggest to compare the IL emitted in both cases using the "ILDASM.EXE"
utility.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #3

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

Similar topics

10
by: Chiller | last post by:
Ok, this is a continuation of a problem I posted on an earlier thread. I've started another thread because my problem has progressed from the initial constructor problem into a general method...
5
by: Chris | last post by:
Hi, I don't get the difference between a struct and a class ! ok, I know that a struct is a value type, the other a reference type, I understand the technical differences between both, but...
12
by: st_ev_fe | last post by:
I've noticed that when constructing a subclass, the base class get's it's contructors called. Is there some way to avoid this? The base class has one variable, which gets initialised to 0. ...
6
by: Peter Hayes | last post by:
I've tried this on another group without any resolution, so let me see if anyone here has an answer - please! ;-) I have a database with which I must communicate queries via a web-based...
5
by: Joe Van Dyk | last post by:
Say I have the following class: using std::string; class Player { public: Player() : name(""), age(""), other_stuff("") {} private: string name; string age;
9
by: 440gtx | last post by:
The class keyword created a lot of confusion that resulted in a popular style that says struct is appropriate for POD (plain old data) and class is appropriate for fancier things (member functions,...
10
by: Joel | last post by:
Is it true that if we don't specify a default constructor for our class, then the C# compiler provides us with its own that zeroes (or assigns default values) to the data members? I wrote a...
4
by: zfareed | last post by:
#include <iostream> #include <fstream> using namespace std; template<class ItemType> class SortedList { private:
5
by: alan | last post by:
Hello world, I'm wondering if it's possible to implement some sort of class/object that can perform mapping from class types to strings? I will know the class type at compile time, like so:...
1
by: costingeana | last post by:
Hi! I am new in Visual C++ and now I face with a problem. I have the below code written into a header file. At compile time I get the following error:
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.