Questions tagged [enum-flags]

167 questions
0
votes
4 answers

Comparing flags with flags - check for matches

Say I have an enum: [Flags] public enum Alpha { NULL = 0, A0 = 1, A1 = 2, A2 = 4, A3 = 8 } And I have the following: Alpha selected = A0 | A1 | A2 Alpha compare = A1 | A3 I want to check if any of the selected flags are also…
simonalexander2005
  • 4,338
  • 4
  • 48
  • 92
0
votes
1 answer

MVC enum flags: Why is the first enum value always true?

So, I have a flagged enum: [Flags] public enum SiteVisibilityFlags : short { None = 0, Corporate = 1, Properties = 2, Kiosk = 4 } Problem is, whatever I set it too, 'None' is always true... no matter what. say I set it like…
Beau D'Amore
  • 3,174
  • 5
  • 24
  • 56
0
votes
2 answers

how to use enum t get multiple values?

I don't know what the right way to do this. But this is what I want. I have an Enum EValue{A=1,B=2,C=4,D=8,E=16,} I need to say int value in database as number , say if select A,c,E need to say 1=4=16 =21 in database. Which is ok but then from 21…
DS2020
  • 279
  • 1
  • 4
  • 20
0
votes
2 answers

restrict possible combination of Flags

is there a way to combine flags within an Enum but to restrict the possible combinations? I have an enum like this: [Flags] public enum CopyFlags { /// /// Copy members regardless of their actual case ///
MakePeaceGreatAgain
  • 35,491
  • 6
  • 60
  • 111
0
votes
3 answers

Deconstruct c# flags within t-sql

I am being asked to build a table with a bunch of bit fields to toggle a series of options. This is a perfect place for a c# flag enum to just combine all of these bits into a single int "options" field in the table. Problem is that there are…
Rikon
  • 2,688
  • 3
  • 22
  • 32
0
votes
1 answer

Display Possible Flags or modify to accommodate to existing flags

I have a piece of code where I get enum flags from an API. When this API changes and updates, I might get values that are not defined in my enum structure. Example: [Flags] public enum TestEnum { Enum1 = 1, Enum2 = 2, Enum3 = 4 } When I…
private_meta
  • 561
  • 4
  • 19
0
votes
2 answers

What is the convention for defining values for enum flags?

Let's say I have following code: [Flags] enum MyFlags { None = 0, A = 1, B = 2, C = 4, D = 8, E = 16, // ... } This is obviously not going to be optimal when the amount of flags grow very large. And by optimal, mean…
Nolonar
  • 5,962
  • 3
  • 36
  • 55
0
votes
2 answers

Determine which checkboxes are checked in a list of checkboxes MVC 5 (editorfor)

This may have been already answered in another thread, but I can't find a solution... so here it goes. I have defined an enum with flags: [Flags] public enum InfarctRelatedVessel { [Description("Left anterior descending")] …
Gabriel
  • 77
  • 7
0
votes
1 answer

JFrame with KeyEventDispatcher Can't click 3 Arrow Keys

I am currently testing the KeyEventDispatcher. Therefore I wrote a little JFrame which implements the KeyEventDispatcher and my own keyPressed and keyReleased Methods. In those Methods, I am using a flag based System to detect only the first…
Loki
  • 4,065
  • 4
  • 29
  • 51
0
votes
1 answer

Generic Enum Flag Parser

I have an array of string values that I would like to have set flags on a Flags Enum object. I have several of these and was looking for a more generic way to pass in the type of the Flags enum and not have to duplicate the method for each Flags…
Josh Taylor
  • 532
  • 2
  • 8
0
votes
2 answers

Using a OR'ed Enum in a custom UITypeEditor

I have a property on a custom control I have written that is an Flag based Enum. I created my own custom control to edit it in a way that makes logical sense and called it from my own UITypeEditor. The problem is that Visual Studio generates an…
Fr33dan
  • 4,227
  • 3
  • 35
  • 62
0
votes
2 answers

How can I get a collection of set bits from an instance of a flags enum?

The Enum class has the following useful function: public static Array GetValues(Type enumType); How could I write something similar to give me a collection of all an enum instance's set bits? With a signature like: public static IEnumerable
Bobby B
  • 2,287
  • 2
  • 24
  • 47
0
votes
2 answers

How to map a Flags enum to multiple combo boxes?

I have to map a Flags Enumeration to multiple combo boxes. For example, the first 2 bits need to correspond to a combo box for screen contrast setting: Bit 0 - 1: Contrast (0=Low / 1 = Medium / 2=high) Bits 2 & 3 need to correspond to the speech…
DaveDev
  • 41,155
  • 72
  • 223
  • 385
0
votes
0 answers

Enum flags combined with Dictionary

Could not find a simple way to define my problem, but I will try to explain it as best I can. I need to be able to represent a selection of predefined items, I have many thousands of these instances of selections in the program, and need a single…
Upperfoot
  • 21
  • 4
-2
votes
2 answers

How to define enum flags in C, without explicitly setting each members value?

In C its common to do... enum { A, B, C, }; However with flags you need to define them explicitly... enum { A = (1 << 0), B = (1 << 1), C = (1 << 2), }; Is it possible to define flags without having to explicitly list each…
ideasman42
  • 42,413
  • 44
  • 197
  • 320
1 2 3
11
12