반응형
Program.cs |
using System; using Hyundai; public class 클래스복습 { public static void Main() { Car car = new Car("현대"); car.Length = 2; //2대 car[0] = "에쿠스"; car[1] = "제니시스"; car.Show(); //에쿠스,제니시스 //예3 CarHandler ch = new CarHandler(car.Show); ch(); //예4 car.Go += car.Show; car.OnGo(); } } |
Car.cs |
//네임스페이스 추가 namespace Hyundai { using System; //Class public class Car { private string name; //Field public Car() //Constructor { //Empty } public Car(string name) { this.name = name; } //Property private int _Length; public int Length { get { return _Length; } set { _Length = value; names = new string[value]; } } //Indexed private string[] names; public string this[int index] { get { return names[index]; } set { names[index] = value; } } public void Show() { //string msg = string.Format() Console.WriteLine("{0}", name); foreach (string s in names) { Console.WriteLine("{0}", s); } } //이벤트 예4 ~Car() { names = null; } //예4 Event public event CarHandler Go; public void OnGo() { if (Go != null) { Go(); } } } //Delegate 예3 public delegate void CarHandler(); } |
결과화면
반응형
'C#' 카테고리의 다른 글
56.C# - 클래스상속 ( ClassInheritance ) (0) | 2009.08.14 |
---|---|
55.C# - namespace ( 네임스페이스 ) (0) | 2009.08.14 |
53.C# - 무명메서드(익명메서드 : Anonymous Method ) (0) | 2009.08.13 |
52.C# - GenericMethod (제네릭 메서드) (0) | 2009.08.13 |
51.C# - Delegate Event (대리자 이벤트) (0) | 2009.08.13 |
Comments