I have a class, it looks like this(ill keep it simple):
now i create instance of this like so:
But what i want to do is set his name right away when i create the instance like this:
What do i have to add to my class to make this possible? I thought i could add a Sub New to my class like this to make it possible but it does not seem to work:
but i just get an error saying "Argument not specified for parameter n"
Can someone help me out please, i just need to know how to set a property of a class right when i instance it
Code:
Public Class Person
Private m_Name as String
Public Property Name() As String
Get
Name = m_Name
End Get
Set(ByVal Value As String)
m_Name = Value
End Set
End Property
End Class
now i create instance of this like so:
Code:
Dim OldMan As New Person
But what i want to do is set his name right away when i create the instance like this:
Code:
Dim OldMan As New Person("Mr. Smith")
What do i have to add to my class to make this possible? I thought i could add a Sub New to my class like this to make it possible but it does not seem to work:
Code:
Sub New(ByVal n as String)
m_Name = n
End Sub
but i just get an error saying "Argument not specified for parameter n"
Can someone help me out please, i just need to know how to set a property of a class right when i instance it