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();
    
  • 相关阅读:
    (hdu 7.1.8)Quoit Design(最低点——在n一个点,发现两点之间的最小距离)
    [Windows]_[0基础]_[使用命令行工具dumpbin分析文件]
    《走开》反馈
    二分基础
    日历的问题C语言,C++(boost),python,Javascript,Java和Matlab实现
    Unity3D 游戏开发架构篇 ——性格一流的设计和持久性
    2015第54周四
    2015第54周三
    2015第54周二
    2015第54周一
  • 原文地址:https://www.cnblogs.com/ouyangkai/p/12753743.html
Copyright © 2011-2022 走看看