Enum.ToString(String)

 myColor.ToString("x") ; ---------------  0000000C      //  8 位的16进制 , 还有 双字节的16 进制  2 byte    or 16 bit

// Sample for Enum.ToString(String)
using System;

class Sample 
{
    enum Colors {Red, Green, Blue, Yellow = 12};

    public static void Main() 
    {
    Colors myColor = Colors.Yellow;

    Console.WriteLine("Colors.Red = {0}", Colors.Red.ToString("d"));
    Console.WriteLine("Colors.Green = {0}", Colors.Green.ToString("d"));
    Console.WriteLine("Colors.Blue = {0}", Colors.Blue.ToString("d"));
    Console.WriteLine("Colors.Yellow = {0}", Colors.Yellow.ToString("d"));

    Console.WriteLine("{0}myColor = Colors.Yellow{0}", Environment.NewLine);

    Console.WriteLine("myColor.ToString(\"g\") = {0}", myColor.ToString("g"));
    Console.WriteLine("myColor.ToString(\"G\") = {0}", myColor.ToString("G"));

    Console.WriteLine("myColor.ToString(\"x\") = {0}", myColor.ToString("x"));
    Console.WriteLine("myColor.ToString(\"X\") = {0}", myColor.ToString("X"));

    Console.WriteLine("myColor.ToString(\"d\") = {0}", myColor.ToString("d"));
    Console.WriteLine("myColor.ToString(\"D\") = {0}", myColor.ToString("D"));    

    Console.WriteLine("myColor.ToString(\"f\") = {0}", myColor.ToString("f"));
    Console.WriteLine("myColor.ToString(\"F\") = {0}", myColor.ToString("F"));
    }
}
/*
This example produces the following results:
Colors.Red = 0
Colors.Green = 1
Colors.Blue = 2
Colors.Yellow = 12

myColor = Colors.Yellow

myColor.ToString("g") = Yellow
myColor.ToString("G") = Yellow
myColor.ToString("x") = 0000000C
myColor.ToString("X") = 0000000C
myColor.ToString("d") = 12
myColor.ToString("D") = 12
myColor.ToString("f") = Yellow
myColor.ToString("F") = Yellow

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值