using System;
/-
//형식 변환 연습
namespace IntergralConversion
{
class HelloWord
{
static void Main()
{
sbyte a = 127;
Console.WriteLine(a);
int b = (int)a;
Console.WriteLine(b);
int x = 128;
Console.WriteLine(x);
sbyte y = (sbyte)x;//int였던 x 를 더 작은 sbyte 인 y 에다가 집어 넣어라.
Console.WriteLine(y);//그랬더니 오버플로우 나서 -128이 된다.
}
}
}
*-
//형식 변환 연습 2
//namespace FloatConversion
//{
// class HelloWorld
// {
// static void Main()
// {
// float a = 69.6875f;
// Console.WriteLine(“a : {{{0}}}”, a);
// double b = (double)a;
// Console.WriteLine(" b : {0}", b);
// Console.WriteLine(“69.6875 == b:{0}”, 69.6875 == b);
// float x = 0.1f;
// Console.WriteLine(“x : {0}”, x);
// double y = (double)x;
// Console.WriteLine(“y : {0}”, y);// 쓰레기값이 들어간다!!
// Console.WriteLine(“0.1 == y : {0} “, 0.1 == y);
// }
// }
//}
//부호 있는 정수 형식과 없는 형식 변환
//namespace SignedUnsingnedConversion
//{
// class HelloWorld
// {
// static void Main()
// {
// int a = 500;
// Console.WriteLine(a);
// uint b = (uint)a; //양수를 부호 없는걸로 캐스팅 해 봐야 같지
// Console.WriteLine(b);
// int x = -30;
// Console.WriteLine(x);
// uint y = (uint)x;//음수를 부호 없는 걸로 캐스팅하면 문제 생김
// Console.WriteLine(y);
// }
// }
//}
//부동 소수점 형식과 정수 형식 사이의 변환
//namespace FloattoIntegral
//{
// class Helloworld
// {
// static void Main()
// {
// float a = 0.9f;
// int b = (int)a;//float 을 int로 만들면 반올림의 자비따위는 없다.
// Console.WriteLine(b);
// float c = 1.1f;
// int d = (int)c;
// Console.WriteLine(d);
// }
// }
//}
// 문자열을 숫자로, 숫자를 문자열로
//namespace StringNumberConversion
//{
// class HelloWorld
// {
// static void Main()
// {
// int a = 123;
// string b = a.ToString();
// Console.WriteLine(b);
// float c = 3.14f;
// string d = c.ToString();
// Console.WriteLine(c);
// string e = “123456”;
// int f = int.Parse(e);
// Console.WriteLine(f);
// string g = “1.23456”;
// float h = float.Parse(g);
// Console.WriteLine(h);
// }
// }
//}
// 상수를 만들어 봅시다.
//namespace Constant
//{
// class HelloWorld
// {
// static void Main()
// {
// const int MAX_INT = 2147483647;
// const int MIN_INT = -2147483648;
// Console.WriteLine(MAX_INT);
// Console.WriteLine(MIN_INT);
// }
// }
//}
//enum을 만들어 봅시다.
namespace Enum
{
class HelloWorld
{
enum DialogResult { YES, NO, CANCLE, CONFIRM, OK }
static void Main()
{
Console.WriteLine((int)DialogResult.YES);
Console.WriteLine((int)DialogResult.NO);
Console.WriteLine((int)DialogResult.CANCLE);
Console.WriteLine((int)DialogResult.CONFIRM);
Console.WriteLine((int)DialogResult.OK);
}
}
}
//nallable 형식
//namespace Nullable
//{
// class HelloWorld
// {
// static void Main()
// {
// int? a = null;
// Console.WriteLine(a.HasValue);//값을 가지고 있느냐?
// Console.WriteLine(a != null);// 값이 널이 아니냐?
// a = 3;
// Console.WriteLine(a.HasValue);//값을 가지고 있느냐?
// Console.WriteLine(a != null);//값이 널이 아니냐?
// Console.WriteLine(a.Value); //a 의 값을 내놓아라
// }
// }
//}
//var 형식을 공부해 보자
namespace UsingVar
{
class HelloWorld
{
static void Main()
{
var a = 20;
Console.WriteLine(“Type : {0}, Value : {1}”, a.GetType(), a);
var b = 3.1414213;
Console.WriteLine(“Type : {0}, Value : {1}”, b.GetType(), b);
var c = “Hello, World!”;
Console.WriteLine(“Type : {0}, Value : {1}”, c.GetType(), c);
var d = new int[] { 10, 20, 30 };
Console.Write(“Type : {0}, Value :”, d.GetType());
foreach (var e in d)
{
Console.Write("{0}”, e);
}
Console.WriteLine();
}
}
}