Possible Duplicate:
C# enums as function parameters?
I was wondering how I can pass an enum type as a method argument.
I'm trying to create a generic method that will take a combo box, and enum, and fill the combo box with each item of the enum.
Enums can not have duplicate values.
Change the signature of the CreateFile method to expect a SupportedPermissions value instead of plain Enum. Show activity on this post. Show activity on this post. First change the method parameter Enum supportedPermissions to SupportedPermissions supportedPermissions .
You can use the operator & ( bitwise and ) and ( | bitwise or ) and use each bit as a bool. Remind that a enum behaves as a int. For example, if the user has pressed the keys W and S. Show activity on this post.
static class Myclass { ... public: enum encoding { BINARY, ASCII, ALNUM, NUM }; Myclass(Myclass::encoding); ... } Then in the method definition: Myclass::Myclass(Myclass::encoding enc) { ... }
I think this is best explained by an example:
Say you have an enum:
enum MyEnum
{
One,
Two,
Three
}
You can declare a method like:
public static void MyEnumMethod(Enum e)
{
var enumValues = Enum.GetValues(e.GetType());
// you can iterate over enumValues with foreach
}
And you would call it like so:
MyEnumMethod(new MyEnum());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With