现在我想做一个多版本的带农历的中国万年历,月历中有星期日、星期一至六,我想使用"星期一","一"或"Monday", "Mon",或"M",但也可能使用其组合,如“星期一Mon”, 于是我定义一个公共Style枚举,里面有ChineseFullName, ChineseShortName, EnglishFullName,EnglishShortName, EnglishSigleLetter等,然后又定义一个公共的ChineseFullName枚举,里面有:星期一,星期二等等,类似的EnglishShortName:Mon,Tue等(类推)。 
因为可能要进行组合,比如Style为:ChineseFullName|EnglishShortName以便得到“星期一MON”的结果,所以考虑使用枚举而未使用数组。
我的问题是:
(1)如果现在选择的是星期五,Style样式为EnglishShortName,如何取得“Fri”的字符串?如果样式Style选择的是EnglishShortName | ChineseShortName,又如何得到“Fri一”呢?
(2)如果EnglishSigleLetter枚举,则其枚举值为:M,T,W,T,F,S,S,很明显,T(Tuesday)与T(Thursday)重复,S(Saturday)与S(Sunday)重复,这在枚举中是不允许的。那么,如何才能正确实现呢?

解决方案 »

  1.   

    using System;public class EnumTest 
    {
    enum Days { Saturday, Sunday, Monday, Tuesday, Wednesday, Thursday, Friday };
    enum BoilingPoints { Celcius = 100, Fahrenheit = 212 };
    [FlagsAttribute]
    enum Colors { Red = 1, Green = 2, Blue = 4, Yellow = 8 }; public static void Main() 
    { Type weekdays = typeof(Days);
    Type boiling = typeof(BoilingPoints); Console.WriteLine("The days of the week, and their corresponding values in the Days Enum are:"); foreach ( string s in Enum.GetNames(weekdays) )
    Console.WriteLine( "{0,-11}= {1}", s, Enum.Format( weekdays, Enum.Parse(weekdays, s), "d")); Console.WriteLine();
    Console.WriteLine("Enums can also be created which have values that represent some meaningful amount.");
    Console.WriteLine("The BoilingPoints Enum defines the following items, and corresponding values:"); foreach ( string s in Enum.GetNames(boiling) )
    Console.WriteLine( "{0,-11}= {1}", s, Enum.Format(boiling, Enum.Parse(boiling, s), "d")); Colors myColors = Colors.Red | Colors.Blue | Colors.Yellow;
    Console.WriteLine();
    Console.WriteLine("myColors holds a combination of colors. Namely: {0}", myColors);
    }
    }
      

  2.   

    (2)如果EnglishSigleLetter枚举,则其枚举值为:M,T,W,T,F,S,S,很明显,T(Tuesday)与T(Thursday)重复,S(Saturday)与S(Sunday)重复,这在枚举中是不允许的。那么,如何才能正确实现呢?一般外国的简写都是Mo,Tu,We,Th,Fr,Sa,Su这样的吧?
      

  3.   

    星期的枚举只有一个,但是可以重载多个ToString方法
      

  4.   

    jamesfay(James Fay):
    你给的代码不知对本问题有何益处?请指点。silentwins(原谅我当天不懂得珍惜只知任性...) :这个我真还不知道哩!
      

  5.   

    现在就是使用数组了,已搞定。效果见这里:
    http://blog.csdn.net/johnsuna/archive/2005/09/26/489515.aspx我觉得应该还有什么更好的方法,但功力不够,暂时无法解决。
      

  6.   

    我的意思是说,不要用你这样的枚举值,明知T和T冲突,为什么不用别的方法呢? Sample Code和好,可以参考他的枚举止的做法
      

  7.   

    这里:
    http://allenlooplee.cnblogs.com/archive/2005/11/12/274519.aspx