C# 检测字符串是否为数字

                 long n;
              1. bool isNumeric = long.TryParse(temp[0], out n);
        2.
var ss = temp[0].All(char.IsDigit); //识别空字符时候 会认为是数字

string str0 = "";
string str1 = " ";
var ss0 = str0.All(char.IsDigit); //true//识别空字符时候 会认为是数字
var ss1 = str1.All(char.IsDigit); //false//识别空字符时候 会认为是数字

if (!id.All(char.IsDigit))//是否是数字
{
return Json(new { msg = "失败!", success = false });
}

            int index_page;
            bool isNumeric = int.TryParse(indexpage, out index_page);
            if (!isNumeric) //不是数字时候
            {
                index_page = 1;
            }
        //检测时间
        public bool CheckStringIsTime(ref string ShortDate)
        {
            DateTime dt;
            if (DateTime.TryParse(ShortDate, out dt))
            {
                ShortDate = dt.ToString("yyyy-MM-dd");
                return true;
            }
            return false;
        }
原文地址:https://www.cnblogs.com/enych/p/9328474.html