본문 바로가기

코딩연습/C#22

[C#]LINQ 데이터 질의 기능 숫자배열로 부터 짝수만을 추출하여 출력 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp13 { class Program { static void Main(string[] args) { //숫자배열로 부터 짝수만을 추출하여 출력 int[] numbers = { 9, 2, 6, 4, 5, 3, 7, 8, 1, 10 }; var result = from n in numbers where n % 2 == 0 //짝수를 만족하는 조건설정 orderby n //n을 정렬하고 select n; //n을 조.. 2020. 6. 12.
[C#]대리자의 이벤트 1.대리자선언(클래스 안 또는 밖) 2.클래스 내에 선언한 대리자의 인스턴스를 event한정자로 수식해서 선언함 3.이벤트 핸들러 작성 4.클래스의 인스턴스 생성하고 이벤트 핸들러를 등록 5. 이벤트가 발생하면 이벤트 헨들러가 호출됨 using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Security.Cryptography.X509Certificates; using System.Text; using System.Threading.Tasks; namespace ConsoleApp12 { class Program { delegate void EventHandler.. 2020. 6. 12.
[C#]대리자 체인 : 여러개의 메소드를 동시에 참조할 수 있음 using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Security.Cryptography.X509Certificates; using System.Text; using System.Threading.Tasks; namespace ConsoleApp12 { class Program { delegate void ThereIsAsFire(string location); //ThereIsAsFire 대리자 선언 static void Call119(string location)//메소드선언 { Console.WriteLine.. 2020. 6. 12.
[C#]대리자(delegate) 대리자에 메소드의 주소를 할당한 후 대리자를 호출하면 대리자가 메소드를 호출해줌 1.대리자를 선언한다. 2.대리자의 인스턴스를 생성:인스터스 생성시 대리자가 참조할 메소드를 매개변수로 넘긴다. 3.대리자를 호출한다 using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Security.Cryptography.X509Certificates; using System.Text; using System.Threading.Tasks; namespace ConsoleApp12 { class Program { delegate int Md(int a, int b); //dele.. 2020. 6. 12.