/// <summary> /// creates a new chain /// </summary> /// <param name="input">Sample set</param> /// <param name="length">window size for sequences</param> /// public DeltaChain(IEnumerable <T> input, int length, SubtractDelegate _subtraction) { subtraction = _subtraction; List <KeyValuePair <T, T> > diffs = GenerateDiffs(input); chain = new Chain <System.Collections.Generic.KeyValuePair <T, T> >(diffs, length / 2); }
static void Main(string[] args) { Student student = new Student(); // student.Add(10, 12); // Student.Subtract(20, 10); DelegateDemo delegateDemo = new DelegateDemo(); AddDelegate d = new AddDelegate(delegateDemo.Add); d(10, 20); SubtractDelegate sd = new SubtractDelegate(DelegateDemo.Subtract); sd.Invoke(20, 10); }
public static void Main(string[] args) { // 기존 방식 AddDelegate <int, int> addDel = (a, b) => Console.WriteLine(a + b); addDel(3, 4); SubtractDelegate <int, int, int> subDel = (a, b) => a - b; Console.WriteLine(subDel(3, 4)); // Action 델리게이트 활용 Action <int, int> actionDel = (a, b) => Console.WriteLine(a + b); actionDel(3, 4); Func <double, double, double> func = (a, b) => a + b; Console.WriteLine(func(3.14, 1651356468)); }
static void Main(string[] args) { // 기존 방식: 사용자 델리게이트 선언 후 참조변수 생성 AddDelegate <int, int> addDel = (a, b) => Console.WriteLine(a + b); addDel(3, 4); SubtractDelegate <int, int, string> subDel = (a, b) => (a - b).ToString(); Console.WriteLine(subDel(3, 4)); // Action 델리게이트 활용 Action <int, int> actionDel = (a, b) => Console.WriteLine(a + b); actionDel(3, 4); //Func 델리게이트 활용: 반환값이 있는 경우 Func <double, double, double> func = (a, b) => a * b; Console.WriteLine(func(3.14, 349586723)); }
static void Main(string[] args) { /* 사용자 정의 delegate 사용 */ AddDelegate <int, int> addFunc = (a, b) => Console.WriteLine(a + b); addFunc(3, 4); SubtractDelegate <double, double, double> subFunc = (a, b) => a - b; Console.WriteLine(subFunc(9, 2)); /* Action 델리게이트 사용 */ Action <int, int> addAction = (a, b) => Console.WriteLine(a + b); addAction(4, 5); /* Func 델리게이트 사용 */ Func <double, double, double> subFunc2 = (a, b) => a - b; Console.WriteLine(subFunc2(9, 8)); }