public static bool ifNumber(object sNum, out long outint)
{
if (sNum == null)
{
outint = 0;
return false;
}
if (long.TryParse(sNum.ToString(), out outint))
return true;
else
return false;
}
解决方案 »
- 如何将浏览器对象设置到MSScriptControl里面啊?
- 急急急急急急 关于存储过程的调用
- 需要解释的问题
- c#中DataGridView控件不能从数据库中读数据
- 关于C#中copy目录
- webform中把txt文件中的内容读入到textbox中的问题,太难!!问题解决马上给分!谢谢各位拉
- 无法为数据库‘hkissp’中的对象‘dbo.t_Record’.‘PK_t_Record’分配空间,因为‘PRIMARY’文件组已满。
- 打开SPREAD控件后, 光标自动在第一个单元格中闪烁,并且单元格为可编辑状态
- 如何通过textbox输入直接向datagridview中添加新行?
- 数据更新的问题!
- 如何判断反射中的 某个方法(MethodInfo) 符合 某个 Delegete 的标准
- 用C#怎么来编码
{
Boolean bRet = false;
if (!String.IsNullOrEmpty(strSrc))
{
if (Regex.IsMatch(strSrc, @"[+-]?\d+"))
{
try
{
Int64 iTemp = Convert.ToInt64(strSrc);
bRet = true;
}
catch
{
}
}
}
return bRet;
}
using System.Collections.Generic;
using System.Text;namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{ string myObj = "a53078323469"; Console.WriteLine(IsNumber(myObj));
Console.ReadLine(); } //判断是否数字
public static bool IsNumber(object sNum)
{
long num; //临时变量
if (sNum == null)
{
return false; //如果传入的值为NULL,返回False
}
if (long.TryParse(sNum.ToString(), out num)) //尝试转换传入的值
return true; //成功返回True
else
return false; //失败返回False
}
}
}
{
Boolean bRet = false;
if (!String.IsNullOrEmpty(strSrc))
{
if (Regex.IsMatch(strSrc, @"^[+-]?\d+$"))
{
try
{
Int64 iTemp = Convert.ToInt64(strSrc);
bRet = true;
}
catch
{
}
}
}
return bRet;
}
{
int b = 123;
if (int.TryParse(str, out b))
{
Response.Write(b);
}
else
{
Response.Write("Failed to Parse to Int");
}
}
有最大/小数的限制么.......如果没什么特别要求 用Convert.ToInt32/64 或 int.TryParse ... 等尝试转换就可以了