x is string str ======x is string 变量名
一个功能,三个表达方式
1 public static string GetValue(object args) { if (args is string str && Regex.Match(str, @"\d\d") is Match mat && mat.Success) return mat.Value; return null; } 2 public static string GetValue2(object args) => ((args is string str && Regex.Match(str, @"\d\d") is Match mat && mat.Success) ?mat.Value:null); 3 Func<object, string> GetValue3Func = args => (args is string str && Regex.Match(str, @"\d\d") is Match mat && mat.Success)?mat.Value:null;