본문 바로가기

분류 전체보기78

[C#]람다식을 이용하여 계산기 클래스 만들기 using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Linq.Expressions; using System.Text; using System.Threading.Tasks; namespace ConsoleApp16 { class Program { class Calculrator //계산기 클래스 생성 { public int Plus(int a,int b) => a + b; public int Minus(int a, int b) => a - b; public int Multiple(int a, int b) => a * b; public double Divide(int a, int b).. 2020. 6. 15.
[C#]식트리 식트리란? 식을 트리로 표현한 자료구조 using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Text; using System.Threading.Tasks; namespace ConsoleApp16 { class Program { static void Main(string[] args) { /* 식트리 */ //1*2+(x-y) Expression const1 = Expression.Constant(1); Expression const2 = Expression.Constant(2); Expression leftExp = Expression.Multiply(con.. 2020. 6. 15.
[C#]람다식(Action대리자 Action대리자: Func대리자와 거의 똑같지만 반환형식이 없음 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp16 { class Program { static void Main(string[] args) { /*Action람다식*/ Action act1 = () => Console.WriteLine("Action()"); act1(); int result = 0; Action act2= (x)=> result =x* x; act2(3); Console.WriteLine(re); Action act3 = (x.. 2020. 6. 15.
[C#]람다식(Func대리자) 람다식이란? 익명 메소드를 만듦 매개변수목록 => 식 원래 () () = delegate (int a, int b) { return a + b; }; 변경>>> () ()= (int a, int b)=>a+b; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp16 { class Program { /*더 간편하게 무명함수 만들기 Func대리자*/ static void Main(string[] args) { Func func1 = () => 10; //입력 매개변수가 없으며, 무조건 10을 반환 Console.Wri.. 2020. 6. 15.