// 调用
1 public event TcpSend Send;
// 定义
2 public delegate void TcpSend(Object sender, ref object o, ref bool b);
原形
1 if (Send != null)
2 Send(this, ref s.obj, ref bSend);
简化
Send?.Invoke(this, ref s.obj, ref bSend);
------------------------------------------------------------
原形
List
List.Add(new Person(10, "test1", 1));
简化
List
{
new Person(10, "test1", 1),
new Person(11, "test2", 1),
new Person(12, "test3", 1),
new Person(13, "test4", 1),
new Person(14, "test5", 1)
};
---------------------------------------------------------------
原形
Person tom1 = new Person();
tom1.Age=10;
tom1.Name="Tom";
简化
Person tom3 = new Person(){ Name="Tom",Age=10};
原形
a == null ? b: a
可以用 COALESCE 表达式,简化成:
简化
a ?? b
原形
AlarmObserver alarmObserver = obj as AlarmObserver;
if (alarmObserver != null)
{
string text = alarmObserver.AlarmInfo.AlarmText;
}
简化
if(obj is AlarmObserver alarmObserver)
{
string text = alarmObserver.AlarmInfo.AlarmText;
}