• 枚举格式化字符串


    使用Enum.ToString(string)方法创建新的字符串对象,以表示枚举成员的数值、十六进制值或字符串值。 此方法采用某个枚举格式化字符串指定希望返回的值。

    下表列出了枚举格式化字符串及其返回的值。 这些格式说明符不区分大小写。

     

    格式字符串

    结果

    G 或 g

    如有可能,将枚举项显示为字符串值,否则显示当前实例的整数值。 如果枚举定义中设置了 Flags 特性,则串联每个有效项的字符串值并将各值用逗号分开。 如果未设置 Flags 特性,则将无效值显示为数字项。 下面的示例阐释 G 格式说明符。

     
    Console.WriteLine(ConsoleColor.Red.ToString("G"));         // Displays Red
    FileAttributes attributes = FileAttributes.Hidden |
                                FileAttributes.Archive;
    Console.WriteLine(attributes.ToString("G"));   // Displays Hidden, Archive                               
    
    
    

    F 或 f

    如有可能,将枚举项显示为字符串值。 如果值可以完全显示为枚举项的总和(即使未提供 Flags 特性),则串联每个有效项的字符串值并将各值用逗号分开。 如果值不能完全由枚举项确定,则将值格式化为整数值。 下面的示例阐释 F 格式说明符。

     
    Console.WriteLine(ConsoleColor.Blue.ToString("F"));       // Displays Blue
    FileAttributes attributes = FileAttributes.Hidden | 
                                FileAttributes.Archive;
    Console.WriteLine(attributes.ToString("F"));   // Displays Hidden, Archive                               
    
    
    

    D 或 d

    以尽可能短的表示形式将枚举项显示为整数值。 下面的示例阐释 D 格式说明符。

     
    Console.WriteLine(ConsoleColor.Cyan.ToString("D"));         // Displays 11
    FileAttributes attributes = FileAttributes.Hidden |
                                FileAttributes.Archive;
    Console.WriteLine(attributes.ToString("D"));                // Displays 34                               
    
    
    

    X 或 x

    将枚举项显示为十六进制值。 按需要将值表示为带有前导零,以确保值的长度最少有八位。 下面的示例阐释 X 格式说明符。

     
    Console.WriteLine(ConsoleColor.Cyan.ToString("X"));   // Displays 0000000B
    FileAttributes attributes = FileAttributes.Hidden |
                                FileAttributes.Archive;
    Console.WriteLine(attributes.ToString("X"));          // Displays 00000022                               
    
    
    
  • 相关阅读:
    centos 查看版本(转)
    防火墙内设置FileZilla Server注意事项
    mycat读写分离与主从切换
    用mycat做读写分离:基于 MySQL主从复制
    mysql处理海量数据时的一些优化查询速度方法
    CentOS下LVS DR模式负载均衡配置详解
    Linux清除arp缓存
    扫描局域网内所有主机和MAC地址的Shell脚本
    Windows+Python 3.6环境下安装PyQt4
    Python 爬虫-豆瓣读书
  • 原文地址:https://www.cnblogs.com/colder/p/3532146.html
Copyright © 2020-2023  润新知