A field is a class-based variable that can be private to the class only depending on the access modifier that you use (e.g. public, protected, private).
A property on the other hand, has get
and set
methods and is used to access a field in a class.
public class ExClass
{
//A field
private string name;
//A property
public string NameProperty
{
get
{
return name;
}
set
{
name = value;
}
}
//Shorthand for creating a property
public string NameProperty2 {get; set;}
}