c# 枚举多选

using System;
public class Test
{
  TrainStyle trainStyle = TrainStyle.Null;
  void Add(TrainStyle ts)
  {
    
trainStyle |= ts;
  }

  void Remove(TrainStyle ts)
  {
    trainStyle &= (~ts);
  }

  bool Contain(TrainStyle ts)
  {
    return (trainStyle & ts)!= 0;
  }
}
[Flags]
public enum TrainStyle
{
    Null = 0,
    G = 1,
    D = 2 << 1,
    T = 2 << 2,
    K = 2 << 3,
    Z = 2 << 4,
    C = 2 << 5,
    Other = 2 << 6
}

 

posted on 2017-11-27 16:17  yungs  阅读(1302)  评论(0)    收藏  举报