C# 7.0的語法主要是優化了以前的寫法,使得更加簡潔方便。try catch when 這個使用場景不多,正常的開發無業務處理的時候不建議使用 。優化
#region 2.字符串嵌入值
Console.WriteLine("____________字符串嵌入值____________");
Console.WriteLine(string.Format("當前時間:{0}", DateTime.Now.ToString()));3d
Console.WriteLine($"6當前時間:{ DateTime.Now.ToString()}");
#endregionorm
#region 3.空值運算符
Console.WriteLine("____________空值運算符____________");
string name = null;
Console.WriteLine(string.IsNullOrEmpty(name) ? "" : name.ToString());//避免空異常blog
string str = string.Empty;
Console.WriteLine(name?.ToString());
#endregion開發
#region 4.異常過濾器
Console.WriteLine("____________異常過濾器____________");
int exceptionValue = 10;
try
{
Int32.Parse("s");
}
catch (Exception e)
when (exceptionValue > 1)//知足條件才進入catch
{
Console.WriteLine("catch");
}
//QuartzManager.addJob("datetimeUpdate", "test", "ConsoleApp.DemoJob", "0/20 * * * * ?");
#endregion
Console.ReadLine();字符串