-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,033
  • 16
  • 71
  • 140

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,574
  • 1
  • 24
  • 40