Arvind Chourasiya

Arvind Chourasiya

  • NA
  • 933
  • 134k

can anyone explain me this piece code?

May 28 2016 9:02 AM
public class Cat : Entity
{
private string _name;
public string Name
{
get { return _name; }
set
{
if (value.Equals(_name))
{
return;
}
_name = value;
OnPropertyChanged();
}
}
}
 
Entity class:
public void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
var handler = PropertyChanged;
handler?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
 
 So here,
1) ^^^
private string _name;
public string Name
{
get { return _name; }
set
{
if (value.Equals(_name))
{
return;
}
_name = value;
OnPropertyChanged();
}
}
 
2)^^^
public string Name{get;set}  
 
so what is the difference between 1 and 2. can replace cat class all code 1^^^ with code 2^^^ 
 

Answers (3)