SamyCode
SamyCode

Reputation: 1018

How to declare automatic properties of get and set as we do in C# but using VB?

Kinda new to Visual Basic.

You know that in C# we would write for example:

public class MyClass
{
    public int Age {get; set;} 
}

I need to do something like that in order to use a class for capture some data and then create a list of this object type. But, how I write a simple Get, Set class in Visual Basic?? Any way to achieve this as simple as we do in C#????? Thank you!!

Upvotes: 0

Views: 180

Answers (3)

Nadeem_MK
Nadeem_MK

Reputation: 7689

  Private _Age as Integer

Public Property Age() As Integer
        Get
            Return _Age 
        End Get
        Set(ByVal value As Integer)
            _Age = value
        End Set
    End Property

Upvotes: 0

David L
David L

Reputation: 33823

There are no curly braces, nor is there an explicit get; set;

Public Property Age As Integer

See MSDN

Upvotes: 2

tinstaafl
tinstaafl

Reputation: 6948

Just declare it as public:

Public Age As Integer = 0

Upvotes: 0

Related Questions