4 ms·
> Others have noted that in many contexts in C# there is a difference, so clients do need to know. Which is why C# added automatic properties. You get the expa
by Guvante 12y ago
> Others have noted that in many contexts in C# there is a difference, so clients do need to know.
Which is why C# added automatic properties. You get the expandability without breaking clients or having to read/write extra code.
public int Foo { get; set; }
- Renaud 12y agoWhich becomes even more useful over a field when you can do: public int Foo { get; private set; }
- marvy 12y agoLast time I checked (long ago), properties in C# don't work as ref or out parameters. Since C# actually distinguishes between ref and out parameters, it would be pretty easy to extend the language such that properties work whenever fields work, but sadly no one but me seems to care.
- Guvante 12y agoSee the following example for why that is excluded. public string Foo { get { return ""; } } private void DoBar(ref string input) { input = "123"; } public void Main() { DoBar(ref Foo); } Typically C# points you towards using a different methodology than ref/out parameters. But I do agree it is annoying when you want to use them.