Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#如何通过设置多个值来使用属性_C# - Fatal编程技术网

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;}
或single
if-ELSE
语句您正在寻找Enum.haslag方法-检查文档使用它的最佳方式是什么,例如通过使用switch或if语句,我的意思是
if(MyFormMode==FormMode.Insert){btnInsert.Enable=false;}
或single
IF ELSE
语句您正在寻找Enum.HasFlag方法-查看文档使用它的最佳方式是什么,例如使用switch或IF语句,我的意思是
IF(MyFormMode==FormMode.Insert){btnInsert.Enable=false;}
或single
IF ELSE
语句您正在寻找Enum.HasFlag方法-查看文档使用它的最佳方式是什么,例如使用switch或IF语句,我的意思是
IF(MyFormMode==FormMode.Insert){btnisert.Enable=false;}
或single
IF ELSE
语句您正在查找Enum.hasvag方法-查看文档