using System;
–
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class HelloWorld
{
static void Main(string[] args)
{
Console.WriteLine(“Hello,World!”);
Console.WriteLine(“Helle,{0}!”, args[0]);
}
}
}
–
namespace IntegralTypes
{
class HelloWorld
{
static void Main(string[] args)
{
sbyte a = -10;
byte b = 40;
Console.WriteLine(“a={0}, b={1}”, a, b);
short c = -3000;
short d = 6000;
Console.WriteLine(“c={{{0}}}, d={1}”, c, d);
int e = -10000000; // 0이 7개지롱
uint f = 300000000; // 부호가 빠져서 0이 8개가 됨
Console.WriteLine(“e={0}, f={1}”, e, f);
long g = -500000000000; // 0이 11개나!
ulong h = 2000000000000000000; //부호가 없으니 0이 18개나 된다.
Console.WriteLine(“g={0}, h={1}”, g, h);
}
}
}
–
–
//오버플로우 테스트
namespace Overflow
{
class HelloWorld
{
static void Main(string[] args)
{
uint a = uint.MaxValue; // 언사인드 인트의 맥스 값을 집어 넣는다.
a += 1; //맥스값에 1을 더한다
Console.WriteLine(a);//a 를 출력한다.
}
}
} // 오버플로우. 값은 0이 나오게 된다.
//부동 소수점의 정밀도
namespace FloatingPoint
{
class MainApp
{
static void Main(string[] args)
{
float a = 3.14159265358979323846f;
Console.WriteLine(a); // float은 소수점 6자리 초과는 짤리게 된다.
double b = 3.14159265358979323846;
Console.WriteLine(b); // double 은 전부 다 표시해 준다.
}
}
}
//데시멀의 정밀도
–
namespace Decimal
{
class HelloWorld
{
static void Main(string[] args)
{
float a = 3.141592653589793238462643383279f;
Console.WriteLine(a);
double b = 3.141592653589793238462643383279;
Console.WriteLine(b);
decimal c = 3.141592653589793238462643383279m;
Console.WriteLine(c);
}
}
} //decimal은 매우 큰 수도 표현할 수 있다.
–
–
//문자를 받아서 좌아악 연결합시다.
namespace Char
{
class MainApp
{
static void Main(string[] args)
{
char a = ‘안’;
char b = ‘녕’;
char c = ‘하’;
char d = ‘세’;
char e = ‘요’;
Console.Write(a);
Console.Write(b);
Console.Write(c);
Console.Write(d);
Console.Write(e);//문자 입력은 줄을 바꾸지 않습니다.
Console.WriteLine();//문자열 입력은 줄을 바꿉니다.
}
}
}
–
–
namespace String
{
class HelloWorld
{
static void Main()
{
string a = “안녕하세요”;
string b = “대마왕입니다.”;
Console.WriteLine(a);
Console.WriteLine(b);
}
}
}
–
//Object는 다양한 형식을 맘대로 받습니다.
namespace Object
{
class HelloWorld
{
static void Main()
{
object a = 123;
object b = 3.141592653589793238462643383279m;
object c = true;
object d = “안녕하세요”;