现在的位置: 首页 > 综合 > 正文

学习摘录2-2

2012年07月17日 ⁄ 综合 ⁄ 共 228字 ⁄ 字号 评论关闭

以下演示的枚举类型让我惊讶,显示出来的居然是字符串形式!
using System;

public enum color
{
 Red, Blue, Green
}

public class m
{
 static void Main()
 {
  Console.WriteLine("color=" + color.Red);
 }
}
执行结果:color=Red
原先我还以为会显示:color=0 之类的。后来找资料才知道,要想让它显示出0,还要这样写:color.Red.ToString("D")

抱歉!评论已关闭.