草庐IT

my_enum_convert

全部标签

C#.Net : Why is my Process. Start() 挂起?

我正在尝试以另一个用户的身份从我的网络应用程序运行批处理文件。由于某种原因,批处理文件挂起!我可以在任务管理器中看到“cmd.exe”在运行,但它永远坐在那里,无法被杀死,批处理文件也没有运行。这是我的代码:SecureStringpassword=newSecureString();foreach(charcin"mypassword".ToCharArray())password.AppendChar(c);ProcessStartInfopsi=newProcessStartInfo();psi.WorkingDirectory=@"c:\build";psi.FileName=

c# - 为什么 Enum.Parse() 返回对象?

这里有很多关于将字符串转换为枚举值的问题。通常,答案看起来类似于thisquestion上的答案。:StatusEnumMyStatus=(StatusEnum)Enum.Parse(typeof(StatusEnum),"Active",true);虽然这是一个非常合理的答案,并且您可以编写一个方法来简化调用,但它没有回答为什么Enum.Parse()返回object的问题。而不是适当的枚举值。为什么我必须将它转换为StatusEnum?编辑:基本上,问题是为什么像这样的函数不是Enum类的一部分?publicstaticTParse(stringvalue)whereT:struc

c# - 为什么 Enum 的 HasFlag 方法需要装箱?

我正在阅读“C#viaCLR”,在第380页上,有一条说明如下:NoteTheEnumclassdefinesaHasFlagmethoddefinedasfollowspublicBooleanHasFlag(Enumflag);Usingthismethod,youcouldrewritethecalltoConsole.WriteLinelikethis:Console.WriteLine("Is{0}hidden?{1}",file,attributes.HasFlag(FileAttributes.Hidden));However,Irecommendthatyouavoid

c# - Convert.ToBase64String/Convert.FromBase64String 和 Encoding.UTF8.GetBytes/Encoding.UTF8.GetString 的区别

我目前正在学习.NET中的对称密码学。我写了一个演示如下:privatebyte[]key=Encoding.ASCII.GetBytes("abcdefgh");privatebyte[]IV=Encoding.ASCII.GetBytes("hgfedcba");privatebyte[]encrypted;publicForm1(){InitializeComponent();}privatevoidbtnEncrypt_Click(objectsender,EventArgse){this.textBox2.Text=this.Encrypt(this.textBox1.Tex

c# - Enum.GetNames() 导致带有负枚举常量的意外顺序

我有以下枚举定义(在C#中):publicenumELogLevel{General=-1,//Shouldonlybeusedindrop-downboxinMerliniaAdministratorlogsettingsAll=0,//Shouldnotbeusedasalevel,onlyasathreshold,effectivelysameasTraceTrace=1,Debug=2,Info=3,Warn=4,Error=5,Fatal=6,Off=7//Shouldnotbeusedasalevel,onlyasathreshold}现在,当我对这种类型执行Enum.Ge

c# - Array 类和 Enum.GetValues() 的简单形式

我正在使用静态方法Enum.GetValues(typeof(SomeEnum));当您需要做的只是枚举值时,此方法非常有用,但出于某种原因,它返回一个非常简单的Array类形式。我正在尝试找到一种简单的方法将其返回值转换为更“正常”的集合类,例如常规数组或List。到目前为止,如果我想这样做,我必须枚举Enum.GetValues(typeof(SomeEnum));的输出。并将它们一一添加到列表。有什么想法可以更干净地做到这一点吗?答案:关键是对返回结果进行强制转换--SomeEnum[]enums=(SomeEnum[])Enum.GetValues(typeof(SomeEnu

c# - : Dictionary<string, object> 或 Dictionary<enum,object> 哪个更快/更有效?

enum类型用作字典键时是否比string类型更快/更有效?IDictionaryorIDictionary事实上,哪种数据类型最适合作为字典键,为什么?请考虑以下事项:注意:为简单起见,只有5个属性structMyKeys{publicstringIncomplete="IN";publicstringSubmitted="SU";publicstringProcessing="PR";publicstringCompleted="CO";publicstringClosed="CL";}和enumMyKeys{Incomplete,Submitted,Processing,Comp

c# - Json Serialize Dictionary<Enum, Int32> 的问题

每当我尝试序列化字典时,我都会得到异常:System.ArgumentException:Type'System.Collections.Generic.Dictionary`2[[Foo.DictionarySerializationTest+TestEnum,Foo,Version=1.0.0.0,Culture=neutral,PublicKeyToken=null],[System.Int32,mscorlib,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089]]'isnotsupportedfors

C# EWS 托管 API : How to access shared mailboxes but not my own inbox

如何连接到交换服务器并从共享邮箱(不是我自己的“myname@mycompany.com”)读取邮件。到目前为止,这是我的代码://CreateaserviceExchangeServiceservice=newExchangeService(ExchangeVersion.Exchange2007_SP1);//Autodiscoverendpointservice.AutodiscoverUrl("someaddress@mycompany.com");FindFoldersResultsfolderSearchResults=service.FindFolders(WellKno

c# - Convert.ToString() 到二进制格式不能按预期工作

inti=20;stringoutput=Convert.ToString(i,2);//Base2formattingi=-20;output=Convert.ToString(i,2);ValueExpectedActual200000000000000000000000000001010010100-201000000000000000000000000001010011111111111111111111111111101100我可以看到20的二进制输出可能已被截断,但我不理解-20的输出。我的期望基于base2表示法加上整数的带符号元素用最左边的第一个数字表示的信念。0表示正