我想在我的枚举上设置空间。这是我的代码示例:publicenumcategory{goodBoy=1,BadBoy}我要设置publicenumcategory{GoodBoy=1,BadBoy}当我检索时,我想从枚举中查看GoodBoy结果 最佳答案 您可以使用DataAnnotations修饰您的Enum值,因此以下内容为真:usingSystem.ComponentModel.DataAnnotations;publicenumBoys{[Display(Name="GoodBoy")]GoodBoy,[Display(Nam
我想在我的枚举上设置空间。这是我的代码示例:publicenumcategory{goodBoy=1,BadBoy}我要设置publicenumcategory{GoodBoy=1,BadBoy}当我检索时,我想从枚举中查看GoodBoy结果 最佳答案 您可以使用DataAnnotations修饰您的Enum值,因此以下内容为真:usingSystem.ComponentModel.DataAnnotations;publicenumBoys{[Display(Name="GoodBoy")]GoodBoy,[Display(Nam
给定以下枚举:publicenumOperations_PerHourType:byte{Holes=1,Pieces=2,Sheets=3,Strips=4,Studs=5}当我运行Microsoft代码分析工具时,它告诉我:CA1028:Microsoft.Design:Ifpossible,maketheunderlyingtypeof'Enums.Operations_PerHourType'System.Int32insteadof'byte'.它永远不会有超过几个可能的值,所以我将它声明为一个字节。为什么他们会推荐使用int32?future可扩展性的更多值(value)?
给定以下枚举:publicenumOperations_PerHourType:byte{Holes=1,Pieces=2,Sheets=3,Strips=4,Studs=5}当我运行Microsoft代码分析工具时,它告诉我:CA1028:Microsoft.Design:Ifpossible,maketheunderlyingtypeof'Enums.Operations_PerHourType'System.Int32insteadof'byte'.它永远不会有超过几个可能的值,所以我将它声明为一个字节。为什么他们会推荐使用int32?future可扩展性的更多值(value)?
这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:CastinttoenuminC#如果我有以下代码:enumfoo:int{option1=1,option2,...}privatefooconvertIntToFoo(intvalue){//ConvertinttorespectiveFoovalueorthrowexception}转换代码是什么样的?
这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:CastinttoenuminC#如果我有以下代码:enumfoo:int{option1=1,option2,...}privatefooconvertIntToFoo(intvalue){//ConvertinttorespectiveFoovalueorthrowexception}转换代码是什么样的?
假设我有以下简单枚举:enumResponse{Yes=1,No=2,Maybe=3}如何将此枚举绑定(bind)到DropDownList控件,以便在列表中显示说明并在选择选项后检索关联的数值(1,2,3)? 最佳答案 我可能不会绑定(bind)数据,因为它是一个枚举,并且在编译时间后它不会改变(除非我有那些愚蠢时刻之一).最好只是遍历枚举:DimitemValuesAsArray=System.Enum.GetValues(GetType(Response))DimitemNamesAsArray=System.Enum.Get
假设我有以下简单枚举:enumResponse{Yes=1,No=2,Maybe=3}如何将此枚举绑定(bind)到DropDownList控件,以便在列表中显示说明并在选择选项后检索关联的数值(1,2,3)? 最佳答案 我可能不会绑定(bind)数据,因为它是一个枚举,并且在编译时间后它不会改变(除非我有那些愚蠢时刻之一).最好只是遍历枚举:DimitemValuesAsArray=System.Enum.GetValues(GetType(Response))DimitemNamesAsArray=System.Enum.Get
我有一个枚举:publicenumMyColours{Red,Green,Blue,Yellow,Fuchsia,Aqua,Orange}我有一个字符串:stringcolour="Red";我希望能够返回:MyColours.Red来自:publicMyColoursGetColour(stringcolour)到目前为止我有:publicMyColoursGetColours(stringcolour){string[]colours=Enum.GetNames(typeof(MyColours));int[]values=Enum.GetValues(typeof(MyColou
我有一个枚举:publicenumMyColours{Red,Green,Blue,Yellow,Fuchsia,Aqua,Orange}我有一个字符串:stringcolour="Red";我希望能够返回:MyColours.Red来自:publicMyColoursGetColour(stringcolour)到目前为止我有:publicMyColoursGetColours(stringcolour){string[]colours=Enum.GetNames(typeof(MyColours));int[]values=Enum.GetValues(typeof(MyColou