zoukankan      html  css  js  c++  java
  • C#:转换类型(待补充)

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace MyCommanHelper
    {
        public class ConvertHelper
        {
    
        #region 方法
    
             // Methods
            public static double ObjectToDouble(object str)
            {
                try
                {
                    if (str == null)
                    {
                        return 0.0;
                    }
                    double result = 0.0;
                    double.TryParse(str.ToString(), out result);
                    return result;
                }
                catch
                {
                    return 0.0;
                }
            }
    
            public static double ObjectToDouble(string str)
            {
                try
                {
                    if ((str == "") || (str == null))
                    {
                        return 0.0;
                    }
                    double result = 0.0;
                    double.TryParse(str, out result);
                    return result;
                }
                catch
                {
                    return 0.0;
                }
            }
    
            public static float ObjectToFloat(object str)
            {
                try
                {
                    if (str == null)
                    {
                        return 0.0f;
                    }
                    float result = 0f;
                    float.TryParse(str.ToString(), out result);
                    return result;
                }
                catch
                {
                    return 0.0f;
                }
            }
    
            public static float ObjectToFloat(string str)
            {
                try
                {
                    if ((str == "") || (str == null))
                    {
                        return 0.0f;
                    }
                    float result = 0f;
                    float.TryParse(str, out result);
                    return result;
                }
                catch
                {
                    return 0.0f;
                }
            }
    
            public static int ObjectToInt(object str)
            {
                try
                {
                    if (str == null)
                    {
                        return 0;
                    }
                    int result = 0;
                    int.TryParse(str.ToString(), out result);
                    return result;
                }
                catch
                {
                    return 0;
                }
            }
    
            public static int ObjectToInt(string str)
            {
                try
                {
                    if (str == null)
                    {
                        return 0;
                    }
                    if (str == "")
                    {
                        return 0;
                    }
                    int result = 0;
                    int.TryParse(str, out result);
                    return result;
                }
                catch
                {
                    return 0;
                }
            }
    
            public static string ObjectToString(object str)
            {
                try
                {
                    if (str == null)
                    {
                        return "";
                    }
                    return Convert.ToString(str);
                }
                catch
                {
                    return "";
                }
            }
    
        #endregion
    
        }
    }
    
  • 相关阅读:
    java基础问题1
    基本数据类型,string类型的瞎扯,final喜欢干的事儿。final string
    关于区块链不懂的东西
    需求更新表属性
    用户体验——响应时间
    后台运行任务nohup xxxxxx &
    jenkins打包maven工程发现有些包下载不下来
    jenkins复选框插件Extended Choice Parameter plugin
    jmeter上传文件tips
    airflow 简介
  • 原文地址:https://www.cnblogs.com/shenchao/p/3673225.html
Copyright © 2011-2022 走看看