-3

I see that i can declare public properties in two ways. Both of them have get / set accessors, but what is the difference between them?

class Job
{
    public int Interval { get; set; }
    public string Key { get; set; }
}

enter image description here

class Job1
{
    public int Interval = 0;
    public string Key = string.Empty;
}

enter image description here

Catalin
  • 11,503
  • 19
  • 74
  • 147

1 Answers1

6

First example is a property - it has declared getter and setter methods.

The second example is a public field, not a property. Public fields are bad coding practice.

toadflakz
  • 7,764
  • 1
  • 27
  • 40