목록분류 전체보기 (29)
미처 완성되지 못한 알고리즘
abstract class Product { } class ConcreteProductA : Product { } class ConcreteProductB : Product { } abstract class Creator { public abstract Product FactoryMethod(); } class ConcreteCreatorA : Creator { public override Product FactoryMethod() { return new ConcreteProductA(); } } class ConcreteCreatorB : Creator { public override Product FactoryMethod() { return new ConcreteProductB(); } } class..
class Sington { private static Sington _instance = null; private Sington() { } public static Sington Instance { get { if (_instance == null) _instance = new Sington(); return _instance; } } public void DrawMessage() { Console.WriteLine("안녕하세요."); } } class Program { static void Main(string[] args) { Sington.Instance.DrawMessage(); }//Main }//class ------------------------------------------------..
Func =>앞에 오는 건 무조건 리턴값이고 그 뒤로는 매개변수 값이다. Action =>Action은 리턴값이 없는 델리게이트 선언이다.
string[] str = new string[100]; str.Where((s) => { if (s.Equals("1")) return true; return false; }).ToArray(); 다음처럼 이름이 없는 함수를 넘기는 것이 가능하다.
public class Student { public int m_num { get; set; } public string m_name { get; set; } } public class StudentList { public List m_list = new List(); Ascending m_sortAscending = new Ascending(); Descending m_sortDescending = new Descending(); public int count { get { return m_list.Count; } } public void Add(Student friend) { m_list.Add(friend); } public void Clear() { m_list.Clear(); } public v..
배열은 선형적인 자료구조이며, 메모리에 순차적으로 잡힌다. int a, int b, int c 이렇게 선언을 할 경우 메모리에 순차적으로 잡힐 수도 있지만, 안 잡힐 수도 있다. 반대로 배열 선언을 하여 배열 변수를 생성할 경우에는 메모리에 무조건 순차적으로 잡힌다. 배열의 선언과 사용법은 간단하나 배열은 단점이 있는 자료구조이기도 하는데, 예를 들어 0x00번지부터 0x0C번지까지 잡힌 int형 3개짜리 배열에서 가운데 값을 삭제를 하면 그 뒷번지 값을 끌어오는 연산에 부담이 생긴다. (3개짜리가 아니라, 1000개라 생각해보라. 가운데 400번째 값을 삭제하면 599개의 값을 순차적으로 끌어오는 것이다.) 여기서 약 599번의 연산이 반복되며 퍼포먼스가 떨어진다. 배열은 논리적일 뿐만 아니라 물리적으..
interface CarControl { void Gear(int i); void Off(); } interface AudioControl { void Volume(int i); void Off(); } public class Car : CarControl, AudioControl { public void Gear(int i ) { Console.WriteLine("현재 기어는 {0}입니다.", i); } public void Volume(int i) { Console.WriteLine("현재 볼륨은 {0}입니다.", i); } void CarControl.Off() { Console.WriteLine("자동차 시동을 껐습니다."); } void AudioControl.Off() { Console.Wri..
자식 클래스를 new 키워드로 인스턴스화 할 때 부모의 디폴트 생성자가 먼저 호출되고 나서 자식 클래스의 생성자가 호출된다.
public event EventHandler Event;