Skip to content

Commit 54d4f2b

Browse files
committed
INotifyPropertyChanged noted
1 parent 494a414 commit 54d4f2b

File tree

1 file changed

+33
-0
lines changed
  • Advanced-C#-Programming/16_Predefined-Interfaces

1 file changed

+33
-0
lines changed

Advanced-C#-Programming/16_Predefined-Interfaces/Program.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,36 @@ public object Clone()
100100
}
101101
*/
102102
#endregion
103+
104+
105+
#region INotifyPropertyChanged Interface
106+
//INotifyPropertyChanged interface is used to notify the subscribers when a property is changed. Is generally used in data binding scenarios.
107+
/*
108+
Person p = new Person { Name = "Hakan", Age = 22 };
109+
110+
p.PropertyChanged += (sender, e) =>
111+
{
112+
Console.WriteLine($"{e.PropertyName} has been changed.");
113+
};
114+
115+
p.Age = 25; // Age has been changed.
116+
public class Person : INotifyPropertyChanged
117+
{
118+
public string Name { get; set; }
119+
int age;
120+
121+
public int Age
122+
{
123+
get => age;
124+
set
125+
{
126+
age = value;
127+
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Age)));
128+
129+
}
130+
}
131+
public event PropertyChangedEventHandler? PropertyChanged;
132+
}
133+
*/
134+
#endregion
135+

0 commit comments

Comments
 (0)