C#如何通过设置多个值来使用属性
我想做这样的事C#如何通过设置多个值来使用属性,c#,C#,我想做这样的事 public partial class Form1 : Form{ // bla bla..... } public enum FormMode { Insert, Update, Delete, View, Print } private FormMode frmMode = FormMode.Insert; public FormMode MyFormMode
public partial class Form1 : Form{
// bla bla.....
}
public enum FormMode {
Insert,
Update,
Delete,
View,
Print
}
private FormMode frmMode = FormMode.Insert;
public FormMode MyFormMode
{
get { return this.frmMode; }
set { this.frmMode = value; }
}
fmDetails.MyFormMode= FormMode.Insert | FormMode.Delete | FormMode.Update;
然后像这样使用它
public partial class Form1 : Form{
// bla bla.....
}
public enum FormMode {
Insert,
Update,
Delete,
View,
Print
}
private FormMode frmMode = FormMode.Insert;
public FormMode MyFormMode
{
get { return this.frmMode; }
set { this.frmMode = value; }
}
fmDetails.MyFormMode= FormMode.Insert | FormMode.Delete | FormMode.Update;
我想这样做。在.net中已经有了这种类型的东西。但是我不知道它们使用什么,如果它是
struct
,enum
或任何其他类型
为了做你正在做的事情,你必须声明一个枚举,如下所示。最重要的是,枚举值都是二的幂,以允许它们在语句中使用,如FormMode.Insert | FormMode.Delete | FormMode.Update
[Flags] //Not necessary, it only allows for such things such as nicer formatted printing using .ToString() http://stackoverflow.com/questions/8447/what-does-the-flags-enum-attribute-mean-in-c
public enum FormMode {
Insert=1,
Update=2,
Delete=4,
View=8,
Print=16
}
为了完成您正在做的事情,您必须声明一个枚举,如下所示。最重要的是,枚举值都是二的幂,以允许它们在语句中使用,如
FormMode.Insert | FormMode.Delete | FormMode.Update
[Flags] //Not necessary, it only allows for such things such as nicer formatted printing using .ToString() http://stackoverflow.com/questions/8447/what-does-the-flags-enum-attribute-mean-in-c
public enum FormMode {
Insert=1,
Update=2,
Delete=4,
View=8,
Print=16
}
为了完成您正在做的事情,您必须声明一个枚举,如下所示。最重要的是,枚举值都是二的幂,以允许它们在语句中使用,如
FormMode.Insert | FormMode.Delete | FormMode.Update
[Flags] //Not necessary, it only allows for such things such as nicer formatted printing using .ToString() http://stackoverflow.com/questions/8447/what-does-the-flags-enum-attribute-mean-in-c
public enum FormMode {
Insert=1,
Update=2,
Delete=4,
View=8,
Print=16
}
为了完成您正在做的事情,您必须声明一个枚举,如下所示。最重要的是,枚举值都是二的幂,以允许它们在语句中使用,如
FormMode.Insert | FormMode.Delete | FormMode.Update
[Flags] //Not necessary, it only allows for such things such as nicer formatted printing using .ToString() http://stackoverflow.com/questions/8447/what-does-the-flags-enum-attribute-mean-in-c
public enum FormMode {
Insert=1,
Update=2,
Delete=4,
View=8,
Print=16
}
使用它的最佳方式是什么,例如通过使用switch或if语句,我的意思是
if(MyFormMode==FormMode.Insert){btnisert.Enable=false;}
或singleif-ELSE
语句您正在寻找Enum.haslag方法-检查文档使用它的最佳方式是什么,例如通过使用switch或if语句,我的意思是if(MyFormMode==FormMode.Insert){btnInsert.Enable=false;}
或singleIF ELSE
语句您正在寻找Enum.HasFlag方法-查看文档使用它的最佳方式是什么,例如使用switch或IF语句,我的意思是IF(MyFormMode==FormMode.Insert){btnInsert.Enable=false;}
或singleIF ELSE
语句您正在寻找Enum.HasFlag方法-查看文档使用它的最佳方式是什么,例如使用switch或IF语句,我的意思是IF(MyFormMode==FormMode.Insert){btnisert.Enable=false;}
或singleIF ELSE
语句您正在查找Enum.hasvag方法-查看文档