As a complement to @John Wu's answer:
In C# 6 and later you can use read-only properties assignable only in the constructor:
public string MyText { get; }
This relieves you from having a backing-field solely for supporting this property.
But the story does not end here, a property is not a field but a method.
Knowing this, it allows you to achieve things a field would not be able to such as:
Notify of value changes by implementing INotifyPropertyChanged
:
using System.ComponentModel;
using System.Runtime.CompilerServices;
public class Test : INotifyPropertyChanged
{
private string _text;
public string Text
{
get => _text;
set
{
if (value == _text)
return;
_text = value;
OnPropertyChanged();
}
}
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
#endregion
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
Being a value you can bind to:
In WPF and UWP you can only bind to properties, not fields.
In the end:
It depends on your requirements.