I am currently defining custom object properties as follows:
private int count;
public int Count
{
get { return count; }
set { Count = value; }
}
my fist part of the question is there any difference between defining fields like that and like:
private int count;
public int Count {get; set;}
unless you want to check something about the value as so:
private int count;
public int Count
{
get { return count; }
set
{
if (value >= 0)
{
count = value;;
}
else MessageBox.Show("Value is negative", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
And the second part is is there a better way of defining object properties in C#?