How to make a property public, but private, set in vb.net?

I just came across this in some C # code ...:

public Foo     Foo    { get; private set; }

How can i do the same in vb?

+3
source share
2 answers

Of course (hits the forehead) ...:

Public Property Foo() As Foo
    Get
        ...
    End Get
    Private Set(ByVal value As Foo)
        ...
    End Set
End Property

I did not think about placing a private keyword there ...

+5
source

VB.NET does not have such automatic properties as C # 3.0. In VB, the equivalent would be:


    Private _Foo As SomeType
    Public Property Foo() As SomeType
        Get
            Return _Foo
        End Get
        Private Set(ByVal value As SomeType)
            _Foo = value
        End Set
    End Property
+4
source

Source: https://habr.com/ru/post/1707099/


All Articles