Olivia Olivia -4 years ago 120
C# Question

Is it ok to skip private fields and just using property in C#?

My lecturer told us to use private fields and public properties. Recently, I was watching a tutorial video. The presenter only created properties. Is it ok to just use the property?

Answer Source

Public properties such as

public string Name { get; set; }

automatically implement private backing fields by the compiler. You never see them, but the effect is the same as manually specified backing fields.

private string name;
public string Name { get { return name; } set { name =value; } }
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download