C#枚举类型

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,即无论这个值是否被用过都会遵守这个规则

posted on 2015-03-23 11:55  wos1239  阅读(84)  评论(0编辑  收藏  举报

导航