一般格式转化处理

来源:互联网 发布:β随机 矩阵 编辑:程序博客网 时间:2024/05/18 09:10

一般情况下的格式处理并不需要太多的考虑,甚至c#还有自动处理格式的方法。。。当然有些时候也会用到自己处理格式的情况,以下就是方法:

internal static class CommonFormater    {        internal static bool TryParselong(string val, out long? result)        {            long outValue;            if (long.TryParse(val, out outValue))            {                result = (long?)outValue;                return true;            }            result = null;            return false;        }        internal static long? TryParselong(string val)        {            long outValue;            if (long.TryParse(val, out outValue))            {                return (long?)outValue;            }            return null;        }        internal static decimal? TryParseDecimal(string val)        {            decimal outValue;            if (decimal.TryParse(val, out outValue))            {                return (decimal?)outValue;            }            return null;        }        internal static bool TryParseDecimal(string val, out decimal? result)        {            decimal outValue;            if (decimal.TryParse(val, out outValue))            {                result = (decimal?)outValue;                return true;            }            result = null;            return false;        }        internal static bool TryParseInt(string val, out int? result)        {            int outValue;            if (int.TryParse(val, out outValue))            {                result = (int?)outValue;                return true;            }            result = null;            return false;        }        internal static bool TryParseDatetime(string val, out DateTime? result)        {            DateTime outValue;            System.IFormatProvider format = new System.Globalization.CultureInfo("zh-CN", true);            if (DateTime.TryParse(val, format, System.Globalization.DateTimeStyles.None, out outValue))            {                result = (DateTime?)outValue;                return true;            }            result = null;            return false;        }    }


0 0