반응형 분류 전체보기553 백준 C# 10811 List 메서드 알아보러 가기 C# - List 메서드 List를 사용하기 위해서는 System.Collections.Generic 네임스페이스를 추가해줘야한다. using System.Collections.Generic; List pig = new List(); 1. Add List 끝 부분에 추가 public void Add (T item); List pig = new List(); pig.Add(2); code-piggy.tistory.com using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace baek2 { class Program { static void Main(string[].. 2023. 4. 18. C# 문법 - Event Delegate 단점 설계적인 부분에서 볼때 Delegate객체를 접근할 수 있으면 호출을 아무나 할 수 있다는 단점이 있다. 이러한 단점을 보완하기위해 Delegate을 mapping하는 Event가 있다. 1. Publisher 01 event처리를 위한 delegate 선언 public delegate void SampleEventHandler(object sender, SampleEventArgs e); public delegate void OnInputKey(); 02 event 선언 public event SampleEventHandler SampleEvent; public event OnInputKey InputKey; OnInputKey -> Delegate InputKey -> Event.. 2023. 4. 18. C# - 중복된 값 제거하기 1. Contains을 사용하기 foreach(int i in list) { if (answer.Contains(i)) continue; answer.Add(i); } 2. Distinct 메서드 사용하기 Distnict 메서드는 System.Linq 네임스페이스에 있으므로 using문에 System.Linq를 추가한다. using System.Linq; List answer = list.Distinct().ToList(); OR var answer = list.Distinct(); 2023. 4. 18. 백준 C# 3052 List 중복된 값 제거하는 법 알아보러 가기 C# - 중복된 값 제거하 1. Contains을 사용하기 foreach(int i in list) { if (answer.Contains(i)) continue; answer.Add(i); } 2. Distinct 메서드 사용하기 Distnict 메서드는 System.Linq 네임스페이스에 있으므로 using문에 System.Linq를 추가한다. using S code-piggy.tistory.com using System; using System.Collections.Generic; using System.Text; namespace baek2 { class Program { static void Main(string[] args) { List list .. 2023. 4. 18. C# 문법 - Delegate(대리자) 1. Delegate 형식은 형식인데, 함수 자체를 넘겨주는 그런 형식! callback 형식 함수 자체를 인자로 넘겨주고 함수를 호출한다. 예시) 사장님(Function)의 비서(Delegate)에게 연락을 요청하지만 받지 않아서 우리의 연락처를 주고 거꾸로(CallBack) 연락을 달라고 요청한다. // OnClicked라는 delegate를 정의 delegate int OnClicked(); 변환 : int, 입력 : void OnClicked이 Delegate 형식의 이름이다. 2. Delegate 예시 01 첫번째 예시 static void ButtonClicked(OnClicked ClickFunction) { // ClickFunction이 참조하는 메서드를 호출한다. ClickFunctio.. 2023. 4. 16. C# 문법 - property(프로퍼티) 1. 은닉성 클래스 내부 필드의 정보 노출을 방지하기 위해 접근 한정자를 protected, private로 선언한다. 외부에서 이 필드에 접근하기 위해서 Set, Get함수를 정의한다. public class testScore { public string name = "piggy"; private int score = 100; // set public void setScore(int x) { score = x; } // get public int getScore() { return score; } } testScore testscore = new testScore(); testscore.setScore(120); int score = testscore.getScore(); Console.WriteLin.. 2023. 4. 16. 이전 1 ··· 78 79 80 81 82 83 84 ··· 93 다음 반응형