I need a sanity check to determine whether my C# compiler is broken or I'm not understanding how automatic properties are supposed to work.
Given the following class definition and constructor, note the respective member values.
public class MyClass
{
public string MyString { get; set; }
public string _anotherString;
public MyClass()
{
MyString = "some value";
// <--- debugger shows MyString as null
_anotherString = "another value";
// <--- debugger shows _anotherString as "another value"
}
}
This continues to happen with a variety of classes. In short, all automatic properties fail to initialize when assigning values in the constructor. They work everywhere else. However, if I change them to use backing stores and initialize the backing variable, they are initialized properly.
Am I correct in assuming that it is always safe to initialize automatic properties in the constructor, or am I missing something? And if it is, then what could be going on with Visual Studio?