I figured I would ask... but is there a way to have the Get part of a property available as public, but keep the set as private?
Otherwise I am thinking I need two properties or a property and a method, just figured this would be cleaner.
I figured I would ask... but is there a way to have the Get part of a property available as public, but keep the set as private?
Otherwise I am thinking I need two properties or a property and a method, just figured this would be cleaner.
I'm not sure what the minimum required version of Visual Studio is, but in VS2015 you can use
It is read-only for public access but can be privately modified using
_Name
I find marking the
property
asreadonly
cleaner than the above answers. I believe vb14 is required.This can be condensed to
https://msdn.microsoft.com/en-us/library/dd293589.aspx?f=255&MSPPError=-2147217396
Yes, quite straight forward:
One additional tweak worth mentioning: I'm not sure if this is a .NET 4.0 or Visual Studio 2010 feature, but if you're using both you don't need to declare the value parameter for the setter/mutator block of code:
If you are using VS2010 or later it is even easier than that
You get the private properties and Get/Set completely for free!
see this blog post: Scott Gu's Blog