开发者

How to validate range of long in .NET 2.0?

I found a solution to validate Long value using extra lib file 'vjslib' as below. I must add another reference DLL file named vjslib.dll.

I know there is some method like Int32.TryParse() something for Int type validate. But I can't find Long.TryPase() directly.

Can anybody help me to find another easy way to validate it with only .NET default lib file?

Appreciated for your input in advance.

using System;
using System.Collections.Generic;
using System.Text;开发者_开发知识库
using java.lang;

namespace DataTypeValidate
{
    class Program
    {
        static void Main(string[] args)
        {
            String value = "1F";

            long min = 0x0;
            long max = 0xFF;

            long n = Long.parseLong(value, 16);

            bool ok = (n >= min) && (n <= max);
            System.Console.WriteLine(ok);

        }
    }
}


You are looking for either Int64.TryParse() or long.TryParse(). There is no such Long type. (The long keyword is a C# alias for the System.Int64 type.)


Have you tried something like

long n = Int64.Parse(value, NumberStyles.HexNumber);

Have a look at

Int64.Parse Method (String, NumberStyles) and

NumberStyles Enumeration

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜