首页 > Windows开发 > 详细

4 C#枚举类型

时间:2015-03-23 12:57:31      阅读:278      评论:0      收藏:0      [点我收藏+]

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace ConsoleApplication1

{    

  class Program    

  {        

    enum SVal        

    {            

      First,   //如果不特别设置,枚举从0开始            

      Second,  //每个后续值为前一个值加1.            

      Third = -5,            

      Fourth        

    }        

    static void Main(string[] args)        

    {                        

      Console.WriteLine("{0}", (int) SVal.Fourth);            

      Console.ReadLine();

          }    

  }

}

每个后续值为前一个值加1.所以输出是-4;

若改为:
    enum SVal        

    {            

      First,   //如果不特别设置,枚举从0开始            

      Second,  //每个后续值为前一个值加1.            

      Third = -1,            

      Fourth        

    }        

输出结果是0,即无论这个值是否被用过都会遵守这个规则

4 C#枚举类型

原文:http://www.cnblogs.com/wos1239/p/4359371.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!