Once you understand what is causing the stack overflow issue is to figure out how to prevent the problem from never happening again.
One way to do this is to adopt a consistent property/field naming convention.
One popular C# naming convention is to name Properties as Pascal case and Fields as camel case with a leading underscore.
In this style, all local variables/ctor or method parameters get named as camel case (without the leading underscore)Code:public string State { get { return _state; } } private string _state;
This avoids having to use 'this.' to disambiguate params from class fields.
vs (when leading underscore isn't used to denote class fields)Code:public Package( string state ) { _state = state; // no problem }
Another way to avoid issues is to use an auto propertyCode:public Package( string state ) { this.state = state; // this works, but it's ugly to some folks }
In fact, auto properties allow you to set access levels. For example, a public readonly property with a private setter would look like this:Code:public string State { get; set; }
Code:public string State { get; private set; }I generally try to use autoproperties whenever possible because it reduces code clutter (imo).Code:public Package( string state ) { State = state; }




Reply With Quote