Search code examples
c#propertiesdefault

Why no initial values on {get;set;} accessors (VS 2010 C#)


This must have been asked many times but I cannot find it....sorry...

Why is the following not permitted?

public string MyString = "initial value" {get; private set;}

(Visual C# Express 2010)


Solution

  • In VS 2017 you can:

        public int Minimum { get; private set; } = 0;
        public int Maximum { get; set; } = 5;