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;

 

posted @ 2018-03-13 23:52  冲天小肥牛  阅读(175)  评论(0编辑  收藏  举报