You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
That's the point of (2). Out of laziness, many of us create immutable from the outside properties when we could make immutable from everywhere. I was thinking this should catch those situations. I'm trying to formalize a test case to clarify.
class Foo
{
int SomeProp { get; private set; }
Foo()
{
this.SomeProp = 100;
}
}
Assume there are other members, but the only place this gets set is in the constructor. Then it could be rewritten like this.
class Foo
{
int SomeProp { get; private set; } = 100;
}
Vannevelj
changed the title
Read-only field can use Auto-Property Initializer instead
Property assigned in constructor can use initializer instead
Jun 3, 2015
Take advantage of C# 6.0's auto-property initializers.
The first case is a lot of (now) unnecessary code. The second is poor man's immutability (and not really all so immutable).
The text was updated successfully, but these errors were encountered: