Is there ever a situation where I should do the following in .NET instead of using a property with read/write capability?
private S as string
public function GetS() as string
return S
end function
public sub SetS(byval NewS as string)
S = NewS
end function
Do properties simply provide a more efficient way for doing the same thing?
Will properties be any slower than the above accessor functions in a high performance application?
Properties, internally, are nothing but a pair of methods. They basically evaluate to a get and set accessor method.
You should use properties, unless the property is going to cause some unexpected, potentially long running side effect, or there is some other good reason to use a method.
For details, I suggest reading the Property Usage Guidelines on MSDN. In particular, use a method when:
Otherwise, I’d use a property. Brad Abram’s blogged some other details, including good reasons why certain API functions use methods (mostly because they could cause cross-computer communication, which would fall into the “side effect” category).