enums

    51热度

    7回答

    Perl有一个枚举类型,它遵循最佳实践,或者更重要的是,它是否需要一个? 我正在使用的项目使用遍布各处的字符串来表示通常使用C#语言中的Enum的东西。例如,我们在哈希的数组,每个电话类型相关的一组电话号码(“家”,“工作”,“手机”等): $phone_number->{type} = 'Home'; 难道是足够在这里使用只读变量集合还是应该使用Enum?我找到了一个enum module

    1热度

    3回答

    的我发现了一段代码(称为非常非常频繁),它将一个枚举值到另一个枚举值,如: public Enum2 ConvertToEnum2(Enum1 enum1) { switch(enum1) { case Enum1.One: return Enum2.One; break; case Enum1.Two: retur

    9热度

    4回答

    如何做一个枚举值和一个应该与枚举名称匹配的字符串的简单比较? 如何将字符串解析为适当的枚举值。 例如, Enum A B=0 C=1 D=2 End Enum 如何检查是否字符串= A.C,我如何转换成字符串及其对应的值,而不相对于一个字符串表示?

    99热度

    12回答

    我有以下代码: // Obtain the string names of all the elements within myEnum String[] names = Enum.GetNames(typeof(myEnum)); // Obtain the values of all the elements within myEnum Array values = Enum.GetV

    4热度

    6回答

    比较来自不同来源的枚举时,比如下面的代码GCC会发出警告。如果没有C风格演员,有没有办法避免这些警告? struct Enumerator { enum { VALUE = 5 }; }; template<int V> struct TemplatedEnumerator { enum { VALUE = V }; }; if(Enumerator::VAL

    9热度

    5回答

    我有使用std::map一些问题: 是使用enum作为std::map一个好的做法的关键?请看下面的代码: enum Shape{ Circle, Rectangle }; int main(int argc, char* argv[]) { std::map<Shape,std::string> strMap; // strMap.insert(S

    13热度

    7回答

    所以我一直在寻找这是在查了一些代码,我得到了所有困惑了: // Amount of days before cancellation can't be done enum Cancellation { Limit = 2 }; 问起是谁检查了在他认为,这是更好的使用枚举而不是静态变量,bettern比家伙这: private static int CANCELLATION_LIMIT = 2

    18热度

    7回答

    你可以传递一个标准的c#枚举作为参数吗? 例如: enum e1 { //... } enum e2 { //... } public void test() { myFunc(e1); myFunc(e2); } public void myFunc(Enum e) { // Iterate through all th

    2热度

    1回答

    我想获取枚举的基础类型的字符串表示形式。 Dim target As System.ConsoleColor = ConsoleColor.Cyan Dim actual = 'What goes here? Dim expected = "11"

    1热度

    1回答

    无论采用哪种方式,在Linq to Sql中对枚举值使用条件运算符时似乎出了点问题。例如 var ret = from listings in db.Listings select new Listing { ID = listings.ID, //etc OrderStatus = listings.OrderItems.Count > 0