zoukankan      html  css  js  c++  java
  • c#类型转换

    类型转换

    序号 方法 & 描述
    1 ToBoolean 如果可能的话,把类型转换为布尔型。
    2 ToByte 把类型转换为字节类型。
    3 ToChar 如果可能的话,把类型转换为单个 Unicode 字符类型。
    4 ToDateTime 把类型(整数或字符串类型)转换为 日期-时间 结构。
    5 ToDecimal 把浮点型或整数类型转换为十进制类型。
    6 ToDouble 把类型转换为双精度浮点型。
    7 ToInt16 把类型转换为 16 位整数类型。
    8 ToInt32 把类型转换为 32 位整数类型。
    9 ToInt64 把类型转换为 64 位整数类型。
    10 ToSbyte 把类型转换为有符号字节类型。
    11 ToSingle 把类型转换为小浮点数类型。
    12 ToString 把类型转换为字符串类型。
    13 ToType 把类型转换为指定类型。
    14 ToUInt16 把类型转换为 16 位无符号整数类型。
    15 ToUInt32 把类型转换为 32 位无符号整数类型。
    16 ToUInt64 把类型转换为 64 位无符号整数类型。

    类型转换 int.TryParse() 方法

    public static bool TryParse(string s, out Int32 result);

    如果转换成功则返回true。否则返回false

    int.TryParse(string s,out int i) 的参数: s是要转换的字符串,i 是转换的结果。

    执行成功返回true,输出转换成功的值;执行失败返回0

    将string类型转换枚举类型

    枚举 字段 = (枚举)Enum.Pares(typeof(枚举),转换的字段);

    实例:QQ state = (QQ) Enum.Pares(typeof(QQ ),str);

    使用 System.Enum 方法发现和操作枚举值

     enum Days { Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday };
    
    string s = Enum.GetName(typeof(Days), 4);
                Console.WriteLine(s);
    
                Console.WriteLine("The values of the Days Enum are:");
                foreach (int i in Enum.GetValues(typeof(Days)))
                    Console.WriteLine(i);
    
                Console.WriteLine("The names of the Days Enum are:");
                foreach (string str in Enum.GetNames(typeof(Days)))
                    Console.WriteLine(str);
                Console.ReadKey();
    
  • 相关阅读:
    最近一月研报推荐次数最多的最热股票
    【2019年07月22日】A股最便宜的股票
    【07月19日】指数估值排名
    北上资金近1周流入排行榜
    主要股东近3年净买入排名
    【07月16日】A股滚动市净率PB历史新低排名
    【07月15日】A股滚动市盈率PE最低排名
    最近3年股息率最高排名
    主要股东近3年净买入排名
    【07月09日】预分红股息率最高排名
  • 原文地址:https://www.cnblogs.com/ouyangkai/p/12753743.html
Copyright © 2011-2022 走看看