0

How can i assign values to auto implemented backing fields like this::

`private string code = "N.A";
      private string name = "not known";
      private int age = 0;

      // Declare a Code property of type string:
      public string Code
      {
         get
         {
            return code;
         }
         set
         {
            code = value;
         }
      }`

how would i accomplish the same thing using auto properties for example:

public string Code { get; set; }

Obviously you cant just add the value directly to the auto property like this:

public string Code = "N.A" { get; set; }

1 Answers1

1

The thing about auto-implemented properties is exactly that they don't have a backing field (available to you).

There are 2.5 solutions to the problem

Jeroen Vannevel
  • 43,651
  • 22
  • 107
  • 170