草庐IT

is_enum_class

全部标签

c# - Enum.Parse() 或 Switch

对于将字符串转换为枚举,以下哪种方式更好?这段代码:colorEnumcolor=(colorEnum)Enum.Parse(typeof(colorEnum),"Green");或者这个:stringcolorString=...colorEnumcolor;switch(colorString){case"Green":color=colorEnum.Green;break;case"Red":color=colorEnum.Red;break;case"Orange":color=colorEnum.Orange;break;....} 最佳答案

c# - 列出标志 Enum 中的所有位名称

我正在尝试创建一个辅助方法来列出枚举值中设置的所有位的名称(用于记录目的)。我想要一个方法来返回在某些变量中设置的所有枚举值的列表。在我的例子中[Flag]EnumHWResponse{None=0x0,Ready=0x1,Working=0x2,Error=0x80,}我给它0x81,它应该给我一个IEnumerable包含{Ready,Error}.由于没有找到更简单的方法,我试着写了下面的代码,但我无法编译。publicstaticIEnumerableMaskToList(Enummask){if(typeof(T).IsSubclassOf(typeof(Enum))==fa

c# - 错误 : A project with an out put type of class library

我试图找出.net并得到这段代码,当我尝试从VS2008运行时它给我这个错误AprojectwithanOutputTypeofClassLibrarycannotbestarteddirectly.Inordertodebugthisproject,addanexecutableprojecttothissolutionwhichreferencestothelibraryproject.Settheexecutableprojectasthestartupproject我正在学习C#,所以不知道该做什么 最佳答案 您不能运行库。

c# - Entity Framework 代码优先 : How to ignore classes

这类似于问题here和here,但这些都是旧的,没有好的答案。假设我有以下类(class):classHairCutStyle{publicintID{get;set;}publicstringName{get;set;}}classCustomerHairCutPreference{publicintID{get;set;}publicCustomerCustomer{get;set;}publicHairCutStyleHairCutStyle{get;set;}}假设我的HairCutStyle数据存储在另一个数据库的一个表中(我从PaulMitchell自己那里得到它)。我想将

c# - "Items collection cannot be modified when the DataSource property is set."

很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visitthehelpcenter.关闭11年前。通过表单将文件添加到txt文件的程序有这个问题,但这个问题没有说明Fstream的任何内容,所以我认为它不必处理它,但我不确定是什么这个问题的意思是。lstEmployees.Items.Add("Norecordsfound.");

c# - 如何在 DataGridViewComboBox 中显示 Enum 类型的成员?

为了在此DatagridViewComboBox中显示ReadAccess枚举成员,我还需要做什么?ReadDataGridViewComboBoxColumn.Items.Clear();ReadDataGridViewComboBoxColumn.Items.AddRange(ReadAccess.None,ReadAccess.Allowed);ReadDataGridViewComboBoxColumn.ValueType=typeof(ReadAccess);这里是设计者生成的关于DataGridView的代码:this.rolesDataGridView.AutoGener

c# - MVC 错误 : The model item passed into the dictionary is null

我只是想建立一个View,但我收到以下错误:System.InvalidOperationException:Themodelitempassedintothedictionaryisnull,butthisdictionaryrequiresanon-nullmodelitemoftype'System.DateTime现在,我知道为什么会出现这种情况,数据库中的特定字段是空值,但它应该是空值,因为这是稍后编辑的内容。这是我的代码:ActionpublicActionResultView(Int64?Id){ModelContainerctn=newModelContainer();

c# - Windows 窗体 : add new line to label if text is too long

我正在使用C#。有时,从Web服务返回的文本(我在标签中显示)太长,会在表单边缘被截断。如果表单不适合标签,是否有简单的方法向标签添加换行符?谢谢 最佳答案 如果您将标签设置为autosize,它会随着您放入其中的任何文本自动增长。为了使其以特定宽度自动换行,您可以设置MaximumSize属性。myLabel.MaximumSize=newSize(100,0);myLabel.AutoSize=true;经过测试并有效。如果您希望始终能够看到数据,可以将Label容器的AutoScroll属性设置为true。

c# - 错误 CS0051(不一致的可访问性 : parameter type 'Job' is less accessible than method 'AddJobs.TotalPay(Job)' )

我通过省略totalFee字段成功编译并运行了下面的源代码。如何将totalFee写入此程序,以便它准确计算每项工作的总费用(费率*时间)?下面,您会看到我尝试使用一种方法;这产生了错误CS0051(可访问性不一致:参数类型“Job”的可访问性低于方法“AddJobs.TotalPay(Job)”)。此源代码是对以下作业的响应:"DesignaJobclassforHarold’sHomeServices.Theclasscontainsfourdatafields—Jobdescription(forexample,“washwindows”),timeinhourstocomple

c# - 电子邮件删除附件后,错误 "The process cannot access the file because it is being used by another process."

我正在做一个电子邮件表单。电子邮件有附件,并在附加文件后发送电子邮件。接下来需要从服务器删除文件。当我试图获取文件时,它给了我主题错误。我什至在删除文件之前调用了GC.Collect(),但错误仍然存​​在。我删除文件的代码是:privatevoidDeleteFiles(DataTabledt){GC.Collect();String[]sAttachments=newString[dt.Rows.Count];try{sAttachments=newString[dt.Rows.Count];for(Int32J=0;J要将文件附加到电子邮件,我的代码是:oMess.Subject