草庐IT

c# - 与 WCF 服务共享枚举

我有几个不同的应用程序,我想在其中共享一个C#枚举。我不太清楚如何在常规应用程序和WCF服务之间共享枚举声明。情况是这样的。我有2个轻量级C#destop应用程序和一个WCFweb服务,它们都需要共享枚举值。客户1有Method1(MyEnume,stringsUserId);客户2有Method2(MyEnume,stringsUserId);网络服务有ServiceMethod1(MyEnume,stringsUserId,stringsSomeData);虽然我最初是创建一个名为Common.dll的库来封装枚举,然后在需要枚举的所有项目中引用该库。但是,WCF使事情变得困难,因

c# - C# 中的字典枚举

我在网上搜索过这个,但找不到我要找的答案。基本上我有以下枚举:publicenumtypFoo:int{itemA:1,itemB:2itemC:3}如何将此枚举转换为字典,以便它存储在以下字典中?DictionarymyDic=newDictionary();myDic看起来像这样:1,itemA2,itemB3,itemC有什么想法吗? 最佳答案 尝试:vardict=Enum.GetValues(typeof(fooEnumType)).Cast().ToDictionary(t=>(int)t,t=>t.ToString()

c# - C# 中的字典枚举

我在网上搜索过这个,但找不到我要找的答案。基本上我有以下枚举:publicenumtypFoo:int{itemA:1,itemB:2itemC:3}如何将此枚举转换为字典,以便它存储在以下字典中?DictionarymyDic=newDictionary();myDic看起来像这样:1,itemA2,itemB3,itemC有什么想法吗? 最佳答案 尝试:vardict=Enum.GetValues(typeof(fooEnumType)).Cast().ToDictionary(t=>(int)t,t=>t.ToString()

c# - 为什么我应该将基础类型设为 Enum Int32 而不是 byte?

给定以下枚举: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)?

c# - 为什么我应该将基础类型设为 Enum Int32 而不是 byte?

给定以下枚举: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)?

C# int 到 enum 的转换

这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:CastinttoenuminC#如果我有以下代码:enumfoo:int{option1=1,option2,...}privatefooconvertIntToFoo(intvalue){//ConvertinttorespectiveFoovalueorthrowexception}转换代码是什么样的?

C# int 到 enum 的转换

这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:CastinttoenuminC#如果我有以下代码:enumfoo:int{option1=1,option2,...}privatefooconvertIntToFoo(intvalue){//ConvertinttorespectiveFoovalueorthrowexception}转换代码是什么样的?

C# 枚举包含值

我有一个枚举enummyEnum2{ab,st,top,under,below}我想写一个函数来测试给定值是否包含在myEnum中类似的东西:privateboolEnumContainValue(EnummyEnum,stringmyValue){returnEnum.GetValues(typeof(myEnum)).ToString().ToUpper().Contains(myValue.ToUpper());}但它不起作用,因为无法识别myEnum参数。 最佳答案 为什么不用Enum.IsDefined(typeof(my

C# 枚举包含值

我有一个枚举enummyEnum2{ab,st,top,under,below}我想写一个函数来测试给定值是否包含在myEnum中类似的东西:privateboolEnumContainValue(EnummyEnum,stringmyValue){returnEnum.GetValues(typeof(myEnum)).ToString().ToUpper().Contains(myValue.ToUpper());}但它不起作用,因为无法识别myEnum参数。 最佳答案 为什么不用Enum.IsDefined(typeof(my

c# - 如何检查枚举是否包含数字?

我有一个这样的枚举:publicenumPromotionTypes{Unspecified=0,InternalEvent=1,ExternalEvent=2,GeneralMailing=3,VisitBased=4,PlayerIntroduction=5,Hospitality=6}我想检查这个枚举是否包含我提供的数字。例如:当我给4时,Enum包含它,所以我想返回True,如果我给7,这个Enum中没有7,所以它返回False。我试过Enum.IsDefine但它只检查字符串值。我怎样才能做到这一点? 最佳答案 IsDef