views:

1043

answers:

3

in C#:

public string Property { get; private set; }

in VB?

Please vote or/and share your ideas!

+4  A: 

Like this:

Private Thingy As Integer
Property Thing() As Integer
    Get
        Return Thingy
    End Get
    Private Set(ByVal value As Integer)
        Thingy = value
    End Set
End Property

Auto property in VB10

Property PartNo As Integer = 44302

But with a private set still can't be done in vb not even in VB10 see here:

From MSDN (as john said):

Property Definitions That Require Standard Syntax :

  • Specify different accessibility for the Get and Set procedure. For example, you might want to make the Set procedure Private and the Get procedure Public.
the_ajp
Shimmy is referring to automatic properties... I don't think this is one.
fretje
It does not exist in vb.net
the_ajp
It will (VS 2010)
fretje
How do I write private set *auto-properties* in VB 10?
Shimmy
@Shimmy, ask that as a question on itself and you are more likely to receive a proper response
Abel
+1  A: 

I don't think that is possible (yet).

See this link on MSDN.
The above article even links to another one about mixed access levels.

I found this on Microsoft Connect, so they are thinking about it (If it will be for VS2010 that's another question).

fretje
Would love to hear how the new mixed access level auto-props will look!
Shimmy
If you read both articles you'll see that mixed access level auto properties will not be available in VS2010
the_ajp
Whoever downvoted this... please explain, thanks!
fretje
In the last link you posted they're talking about a ReadOnly property this is a property 'without' a Set not a Private Set. So still no mixed access level auto properties in vs2010.
the_ajp
Isn't a readonly property in vb equivalent with a private set in C#? You have to be able to set the variable somewhere, don't you? And as we're talking about auto-properties, being properties without a private backing field (or rather "with one that's generated on the fly").
fretje
You do have to set the variable somwhere but the equivalent of a readonly property in c# is public string Property { get; } Which is impossible as it will be in vb. In the current vb autoprop syntaxt it is afaics impossible to make a private or internal set. If you read the article at your last post and see the proposed solution you'll see it's as I say.
the_ajp
+2  A: 

According to this MSDN article, you can't:

Auto-implemented properties are convenient and support many programming scenarios. However, there are situations in which you cannot use an auto-implemented property and must instead use standard, or expanded, property syntax.

You have to use expanded property-definition syntax if you want to do any one of the following:

[...]

  • Specify different accessibility for the Get and Set procedure. For example, you might want to make the Set procedure Private and the Get procedure Public.
Jon Skeet