[ C#. DataType ]
1. 데이터 형식 종류
- 숫자형
- 구조체(struct)
- 열거형(enum)과 같은 값 형식
- 문자열
- 클래스
2. 값 형식(Value Type)
- 숫자형 : sbyte, short, int, long, byte, ushort, uint, ulong, float, double, decimal
- bool
- char
- struct
- enum 등
3. 참조 형식(Reference Type)
- string
- object
- class 등
4. 형식(Value Type)
- 닷넷에서 문자는 한글/영문 구분 없이 모든 한 문자는 16비트 유니코드 문자이다
- C#에서 형식을 선언할 때 C#형식 혹은 System 네임스페이스에 있는
닷넷 프레임워크 형식으로 표현이 가능하다.
이 둘간의 차이점은 C# 표현은 닷넷 프레임워크 형식 표현의 별칭이다.
닷넷 초기 이 둘간의 표현 방법이 어느 것이 좋으며,
성능상에 유리한지에 대해 의견이 분분한적이 있다.
결론적으로 각 언어 별로 예전부터 형식에 대해 표현해 오던 방식이 있으며,
좀더 간략히 표현하는 것일 뿐 성능상의 차이는 존재하지 않는다.
1. Type
1. int, string, char, bool, double, 상수
2. double = 3.141592;
3. const double PI = 3.14
4. string[] ages = new String[] {"10", "30", "40", "50"};
int[] n = new int[100];
int len = ages.Length;
method인자 ( static voic method_name(int[] arr) { ... }
string[,] arr = new string[,] { {"김씨","32"}, {"이씨", "13"), {"최씨", "52"}};
2.열거형
a. 선언
enum CalcType
{
Add = 1,
Substract,
Multiply,
Devide
}
b. 부여된값
위와 같이 기술시 아래 같은 index가 부여 됨
{
Add = 1,
Substract=2,
Multiply=3,
Devide=4
}
c. 사용
상수처럼 사용할 수 있음
if (Calctype.Substract == 변수){
...
}
3. 구조체
a. 선언
struct Rect
{
public int Left; --public, Private변수들은 모두 첫번째 번수는 대문자로 함
public int Top;
public int Height;
public int Width;
public Rect(int left, int top, int hegith, int width)
{
Left = left;
Top = top;
Height = height;
Width = width;
}
}
b. 기본 type : value type
만들어지는 메모리 위치 : stack
(참고 class는 refrence type이면서 메모리 위치는 : heap메 만들어짐)
c. 값 부여하기
Rect r = new Rect();
r.Left = 10;
r.Top = 10;
r.Height = 100;
r.Width = 100;
Rect r2 = new Rect(20, 20, 200, 200);
'C# > Data Type' 카테고리의 다른 글
C#. DataType-Nullable (0) | 2018.02.02 |
---|