Dailelog
3. C# 기본형 본문
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
/*
* built-int type 변수 특징
* -의미: 정수를 저장하는 거억장소
* -목적: 셀수 있는 숫자 저장
* 학생수, 지갑의 돈, 자동차 수 소수점 없음
* -상수: 1234. 0x7f12. 0755
* -크기: 4바이트
* -표형양식: 양수경우/음수경우
* -연산자: +-* %(modulo operator)
* -주의사항: overflow / truncation
* -short(ushort):2 bytes
* -long(ulong: 8bytes
*
* 문자형 변수(character variable)
* - 2 bytes unicode
*
* 실수형 변수(floating number variable)
* -float: 4bytes
* -double: 8bytes
* -decimal:16bytes (소수점 28~29자리)
*
* 불린 변수 (bool variable)
* - 상수 : true/ false
* -비교문 type checking 강화
*
* [잡다한 변화]
* 매크로 정의 -> 정적 데이터 멤버 /#define max (100) 같이 define을 사용하지 못한다. 클래스 외부에 선언불가능
* 변수 정의 순서
* 함수 이름 중복(function overloading)
* 한글 변수명
* is 연산자를 이용한 type checking
* as 연사자를 이용한 type casting
* format 문의 대동: {0} {1} {2} ....
*/
namespace BasicTypes
{
class Program
{
static int MAX = 100; //매크로 대용
static void Main(string[] args)
{
decimal x;
Console.WriteLine(sizeof(int));
Console.WriteLine(sizeof(decimal));
Console.WriteLine(sizeof(bool));
x = 12.746489487463474111M;
Console.WriteLine(x);
bool b = true;
Console.WriteLine(b);
int i = MAX;
if( i == 10) // i = 10 은 c언어에서는 = 가 대입이라서 요류가 생긴다. 블린변수 사용하기
{
Console.WriteLine("same");
}
else
{
Console.WriteLine("not same");
}
//변수 정의 순서
int a;
a = 10;
a++;
Console.WriteLine(a);
//한글 변수명 가능한 영어 사용 평생 사용할 일없음
int 돈;
돈 = 10;
돈++;
Console.WriteLine(돈);
//is 연산자를 이용한 type checking 특정타입인지를 확인하하는 연산자
if (a is double)
{
Console.WriteLine("a 는 실수형이다.");
}
else
{
Console.WriteLine("a 는 실수형이 아니다.");
}
//as 연사자를 이용한 type casting 보통 레퍼런스 타입의 type casting할때사용
a = (int)89.1; //이건 원래하는type casting
//format 문의 대동: {0} {1} {2} ....
Console.WriteLine("a= " + a + "\n 돈= " + 돈); //원래
Console.WriteLine("a = {0}\n돈 = {1}", a, 돈); //format 활용한것
int[] arr = { 100, 300, 500, 200, 400 };
foreach(int p in arr) //arr 배열의 모든 원소
{
Console.WriteLine(p);
}
}
}
}
'언어 > CS' 카테고리의 다른 글
4.Recursive Function 재귀함수 (3) | 2022.09.07 |
---|---|
2.namespace (2) | 2022.09.02 |
1.C-> C# (sum) (0) | 2022.09.02 |