我建议在这种情况下使用枚举,你可以用枚举做很多事情,我举一个例子:
枚举定义:
public enum Month
{ Jan=1, Feb, Mar, Apr, may, Jun, Jul, Aug, Sep, Oct, Nov, Dec }
在按钮点击:
Month current = Month.Jan; //staticly checking a month
if(current == Month.Jan)
MessageBox.Show("It's Jan");
else
MessageBox.Show("It's not Jan.");
List<Month> specialMonthes = new List<Month>();
specialMonthes.Add(Month.Oct);
specialMonthes.Add(Month.Apr);
specialMonthes.Add(Month.Jan);
//Search the list for the month we are in now
foreach (Month specialMonth in specialMonthes)
{
if ((int)specialMonth == DateTime.Now.Month) //dynamically checking this month
MessageBox.Show(string.Format("It's {0} now & {0} is a special month.",
specialMonth));
//Output: It's Jan now and Jan is a special month.
}
你可以化解,你可以比较,你可以施放。
那么为什么不使用枚举呢?有了车就不用跑了。