Class member initial values.

  • Thread starter Thread starter Qwert
  • Start date Start date
Q

Qwert

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.
 
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
 
Qwert said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top