'C#/Grammar'에 해당되는 글 2건

Bit Enum (Flag)

C#/Grammar 2017. 10. 1. 07:28
Bit 연산을 위한 Enum 을 만들수 있다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using System;
 
 
public class TestEnum
    {
        [Flags]
    enum BitEnum
    {
        Zero = 0,
        One = 1,
        Two = 2,
        Four = 4,
        Eight = 8
    }
        public TestEnum()
        {
            // AND operator
            BitEnum e1 = BitEnum.One & BitEnum.Four;
            Console.WriteLine(e1);
 
 
            if (e1.HasFlag(BitEnum.One))
            {
 
            }
 
 
 
            // OR operator
            BitEnum e2 = BitEnum.One | BitEnum.Four;
            Console.WriteLine(e2);
 
            // << operator
            byte e3 = 8 << 1;
            Console.WriteLine(e3);
            // >> operator
            byte e4 = 8 >> 1;
            Console.WriteLine(e4);
 
 
 
        }
    }



'C# > Grammar' 카테고리의 다른 글

C# 에서 사용되는 데이터 타입.  (0) 2017.09.25
블로그 이미지

SuperNatural2

여전히 프로그래밍이 즐거운 사람 입니다

,

C# 에서 사용되는 데이터 타입



아래 테이블의 Short Name 과 .NET Class 타입 모두 사용가능 하다. 

컴파일러는 컴파일시 Short Name 을 .NET Class 로 변환하는 과정을 거치게 된다.




Built-In Data Types

Short Name

.NET Class

Type

Width

Range (bits)

byte

Byte

Unsigned integer

8

0 to 255

sbyte

SByte

Signed integer

8

-128 to 127

int

Int32

Signed integer

32

-2,147,483,648 to 2,147,483,647

uint

UInt32

Unsigned integer

32

0 to 4294967295

short

Int16

Signed integer

16

-32,768 to 32,767

ushort

UInt16

Unsigned integer

16

0 to 65535

long

Int64

Signed integer

64

-9223372036854775808 to 9223372036854775807

ulong

UInt64

Unsigned integer

64

0 to 18446744073709551615

float

Single

Single-precision floating point type

32

-3.402823e38 to 3.402823e38

double

Double

Double-precision floating point type

64

-1.79769313486232e308 to 1.79769313486232e308

char

Char

A single Unicode character

16

Unicode symbols used in text

bool

Boolean

Logical Boolean type

8

True or false

object

Object

Base type of all other types

string

String

A sequence of characters

decimal

Decimal

Precise fractional or integral type that can represent decimal numbers with 29 significant digits

128

±1.0 × 10e−28 to ±7.9 × 10e28


출처 : https://msdn.microsoft.com/en-us/library/ms228360(v=vs.90).aspx


'C# > Grammar' 카테고리의 다른 글

Bit Enum (Flag)  (0) 2017.10.01
블로그 이미지

SuperNatural2

여전히 프로그래밍이 즐거운 사람 입니다

,