実装例:
private void button1_Click(object sender, EventArgs e) { for(int i = 0; i < 10; i++) { //C# 5.0 まで Debug.WriteLine(string.Format("値は {0} です。", i)); //C# 6.0 以降 Debug.WriteLine($"値は {i} です。", i); } }
リンク:
C# プログラミング
private void button1_Click(object sender, EventArgs e) { for(int i = 0; i < 10; i++) { //C# 5.0 まで Debug.WriteLine(string.Format("値は {0} です。", i)); //C# 6.0 以降 Debug.WriteLine($"値は {i} です。", i); } }
public class NotificationObject : INotifyPropertyChanged { /// <summary> /// プロパティ値の変更をクライアントに通知する。 /// </summary> public event PropertyChangedEventHandler PropertyChanged; /// <summary> /// PropertyChanged イベント を発生させる。 /// </summary> /// <param name="propertyName">変更されたプロパティ名</param> protected void OnPropertyChanged([CallerMemberName] string propertyName = "") { // C# 6 の Null 条件演算子を利用 this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); // C# 6 以前 //if (this.PropertyChanged != null) //{ // this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); //} } }
public class MyClass : NotificationObject { private string _text; public string Text { get { return _text; } set { this._text = value; this.OnPropertyChanged(); } } public MyClass() { } }Null 条件演算子 (C# および Visual Basic)