I realize that it seems to be a duplicate of What is the difference between a Field and a Property in C#? but my question has a slight difference (from my point of view):
Once I know that
Is there any difference (except the style/future development ones), like some type of control in setting the property?
Is there any additional difference between:
public string MyString { get; set; }
and
public string myString;
(I am aware that, that the first version requires C# 3.0 or above and that the compiler does create the private fields.)
Fields and properties look the same, but they are not. Properties are methods and as such there are certain things that are not supported for properties, and some things that may happen with properties but never in the case of fields.
Here's a list of differences:
out/ref
arguments. Properties can not. DateTime.Now
is not always equal to itself.readonly
)MemberTypes
so they are located differently (GetFields
vs GetProperties
for example)