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
    
        }
    }
    
  • 相关阅读:
    powershell,系统学习的第一种脚本语言
    mysql的source命令
    timer--计时器
    document.write 方法
    数组去重
    Abdicate
    轮播图
    使用 margin 让div块内容居中
    模运算 NOJ 1037
    模运算 NOJ 1037
  • 原文地址:https://www.cnblogs.com/shenchao/p/3673225.html
Copyright © 2011-2022 走看看