으미 어렵다 슬슬
==========================================
//////this 키워드
//////자기 자신의 필드나 메소드에 접근할 때 this 키워드를 사용한다.
////using System;
////namespace This
////{
//// class Employee
//// {
//// private string Name;
//// private string Position;
//// public void SetName(string Name)
//// {
//// this.Name = Name;
//// }
//// public string GetName()
//// {
//// return Name;
//// }
//// public void SetPositon(string Position)
//// {
//// this.Position = Position;
//// }
//// public string GetPosition()
//// {
//// return this.Position;
//// }
//// }
//// class HelloWorld
//// {
//// static void Main(string[] args)
//// {
//// Employee pooh = new Employee();
//// pooh.SetName(“pooh”);
//// pooh.SetPositon(“waiter”);
//// Console.WriteLine("{0} {1}", pooh.GetName(), pooh.GetPosition());
//// Employee tigger = new Employee();
//// tigger.SetName(“tigger”);
//// tigger.SetPositon(“Cleaner”);
//// Console.WriteLine("{0} {1}", tigger.GetName(), tigger.GetPosition());
//// }
//// }
////}
////this 생성자
//using System;
//namespace ThisConstructor
//{
// class Myclass
// {
// int a, b, c; // 맴버변수는 굳이 초기화 하지 않아도 기본값이 0 이 들어가고, 쓰레기값이 들어가지 않는다.
// public Myclass()
// {
// this.a = 5425;
// Console.WriteLine(“Myclass()”);
// }
// public Myclass(int b) : this()
// {
// this.b = b;
// Console.WriteLine(“MyClass({0})”, a);
// }
// public Myclass(int b, int c)
// : this(b)
// {
// this.c = c;
// Console.WriteLine(“Myclass({0} . {1})",b,c);
// }
// public void PrintFriends()
// {
// Console.WriteLine(“a:{0}, b:{1}, c:{2}”, a, b, c);
// }
// }
// class HelloWorld
// {
// static void Main(string[] args)
// {
// Myclass a = new Myclass();
// a.PrintFriends();
// Console.WriteLine();
// Myclass b = new Myclass(1);
// b.PrintFriends();
// Console.WriteLine();
// Myclass c = new Myclass(10, 20);
// c.PrintFriends();
// Console.WriteLine();
// }
// }
//}
////접근 한정자로 공개 수준 결정하기
//using System;
//namespace AccessModifier
//{
// class WaterHeater
// {
// protected int temperature;
// public void SetTemperature(int temperature)
// {
// if (temperature < -5 || temperature > 42)
// {
// throw new Exception(” 온도 범위를 벗어났습니다 “);
// }
// this.temperature = temperature;
// }
// internal void TurnOnWater()
// {
// Console.WriteLine ( “Turn on Water : {0} " , temperature);
// }
// }
// class HelloWorld
// {
// static void Main (string[] args)
// {
// try
// {
// WaterHeater heater = new WaterHeater();
// heater.SetTemperature(20);
// heater.TurnOnWater();
// heater.SetTemperature(-2);
// heater.TurnOnWater();
// heater.SetTemperature(50);
// heater.TurnOnWater();
// }
// catch (Exception e)
// {
// Console.WriteLine(e.Message);
// }
// }
// }
//}
////상속받기 연습
//using System;
//namespace Inheritance
//{
// class Base
// {
// protected string Name;
// public Base(string name) // 생성자
// {
// this.Name = name;
// Console.WriteLine("{0}.Base()”, this.Name); //생성자에 넣은 명령이니 초기에 바로 실행되어 버릴 거다.
// }
// ~Base()
// {
// Console.WriteLine("{0}.~Base()”, this.Name);
// }
// public void BaseMethod()
// {
// Console.WriteLine("{0}.BaseMethod()", Name);
// }
// }
// class Derived : Base
// {
// public Derived(string Name) : base(Name) //Base 의 초기값에 접근하기 위해 base 명령을 썼네요.
// {
// Console.WriteLine("{0}.Derived()", this.Name); // 역시 생성자임. 초기값을 넣어주고 있네요
// }
// ~Derived()
// {
// Console.WriteLine("{0}.~Derived()", this.Name);
// }
// public void DerivedMethod()
// {
// Console.WriteLine("{0}.DerivedMethod()", this.Name);
// }
// }
// class HelloWorid
// {
// static void Main(string[] args)
// {
// Base a = new Base(“a”); // 처음에 생성자가 실행되면서 자동으로 씌여지는게 있음.
// a.BaseMethod();
// Derived b = new Derived(“b”);
// b.BaseMethod();
// b.DerivedMethod();
// }
// }
//}
////기반 클래스와 파생 클래스 사이의 형식 변환. 그리고 is와 as
//using System;
//namespace TypeCasting
//{
// class Mammal
// {
// public void Nurse()
// {
// Console.WriteLine(“Nurse()”);
// }
// }
// class Dog : Mammal
// {
// public void Bark()
// {
// Console.WriteLine(“Bark()”);
// }
// }
// class Cat : Mammal
// {
// public void Meow()
// {
// Console.WriteLine(“Meow()”);
// }
// }
// class HelloWorlds
// {
// static void Main(string[] args)
// {
// Mammal mammal = new Dog(); //새로운 dog 클래스를 선언하고 이것에 소속된 mamamal 클래스만 사용하겠다고 하면서 집어 넣는다.
// Dog dog;
// if (mammal is Dog) //mammal은 dog 인가
// {
// dog = (Dog)mammal;
// dog.Bark();
// }
// Mammal mamma12 = new Cat();
// Cat cat = mamma12 as Cat; //as 는 형식 변환 연산자와 같은 일을 하지만 예외가 발생하거나 제대로 되어 있지 않으면 null을 리턴한다.
// if (cat != null)
// cat.Meow();
// Cat cat2 = mammal as Cat; //mammal은 Dog 클래스 입니다.
// if (cat2 != null)
// cat2.Meow();
// else
// Console.WriteLine(“cat2 is not a Cat : cat2는 Cat 클래스가 아닙니다”);
// }
// }
//}
////오버라이딩과 다형성
//using System;
//namespace Overriding
//{
// class ArmorSuite
// {
// public virtual void Initialize()
// {
// Console.WriteLine(“Armored”);
// }
// }
// class IronMan : ArmorSuite
// {
// public override void Initialize()
// {
// base.Initialize();
// Console.WriteLine(“Repulsor Rays Armed”);
// }
// }
// class WarMachine : ArmorSuite
// {
// public override void Initialize()
// {
// base.Initialize();
// Console.WriteLine(“Double-Barrel Cannon Armd”);
// Console.WriteLine(“Micro-Rocket Launcher Armd”);
// }
// }
// class HelloWorld
// {
// static void Main(string[] args)
// {
// Console.WriteLine(“Creating Armorsuite…..”);
// ArmorSuite armosuite = new ArmorSuite();
// armosuite.Initialize();
// Console.WriteLine("\nCreating Atmorsuite…..");
// ArmorSuite ironman = new IronMan();
// ironman.Initialize();
// Console.WriteLine("\nCreating Atmorsuite…..");
// ArmorSuite warmachine = new WarMachine();
// warmachine.Initialize();
// }
// }
//}