UncleRonin
Well-known member
I'm busy designing a class and a strange thought occurred to me. When you create a class, is it better to declare and set variables directly in the class space or to set them in the New() method? I don't know all that much about the compiler or the way everything is finally put together so I'm absolutely clueless. Maybe one method is faster or one is more suited to a particular situation? Or maybe it all depends on the data type itself?
So which should be used and why (if there is a difinitive reason)
OR
So which should be used and why (if there is a difinitive reason)
VB.NET:
Public Class Test
Private Int as Integer = 100
Private Str as String = "Test"
Private Obj as Object = SomeObjectThingy
End Class
VB.NET:
Public Class Test
Private Int as Integer
Private Str as String
Private Obj as Object
Public Sub New()
Int = 100
Str = "Test"
Object = SomeObjectThingy
End Sub
End Class