What exactly does this mean in C #?

I am looking at the open source .NET twain shell and have seen this:

[Flags]
internal enum TwDG : short
{                                   // DG_.....
    Control = 0x0001,
    Image = 0x0002,
    Audio = 0x0004
}

What exactly does this Flag decorator mean? (Is this called a "decorator"?)

Also, what does the short mean at the end of a listing ad mean?

Thank!

+3
source share
10 answers

short is another keyword for System.Int16, a two-byte integer from -32.768 to 32.767. By default, the base type of an enumeration is int; in this case, they try to use a smaller data type to store enumerator values.

+1
source

.

.

, , URL

+8

. , , , . .

, ToString() , , . " | | ", "7".

"short" , 16- .

+3

, , "" .

var flags = TwDG.Control | TwDG. Image;
Console.WriteLine(flags.HasFlag(TwDG.Image));   // true
Console.WriteLine(flags.HasFlag(TwDG.Control)); // true
Console.WriteLine(flags.HasFlag(TwDG.Audio));   // false

FlagAttribute (Enum.HasFlag Framework 4.0)

Short , back-type int ( ), . long, ushort .

+2

-.
, .
:

TwDG value = TwDG.Control | TwDG.Image | TwDG.Audio;

7.

2^n. , :

[Flags]
public enum Sides
{
    Left = 1,
    Right = 2,
    Up = 4,
    Down = 8,

    LeftAndRight = 3,
    UpAndDown = 12,

    AllSides = 15
}
+1

Flags - ; System.FlagsAttribute.

, TwDG , .. , , , :

var control = TwDG.Control;
var allTogether = TwDG.Control | TwDG.Image | TwDG.Audio;

, , - ( ) , . , , , . :

var imageAndAudio = TwDG.Image | TwDG.Audio;
var muteImage = TwDG.Image;

, , , "" Audio :

var hasAudio = (myValue & TwDG.Audio) != (TwDG) 0;
0

, ( ), ; . "" .
MSDN.

0

As for [Flag] - you should see the link text here

The short data time used to store enumeration values.

0
source

Source: https://habr.com/ru/post/1777940/


All Articles