C# (72) 썸네일형 리스트형 event using System; namespace HelloWorld { class App { //1.class내부에 event키워드로 대리자형식을 정의한다 public event EventHandler AnimationCompleteHandler; //생성자 public App() { } public void PlayAnimation() { for (int i = 0; i < 5; i++) { Console.WriteLine("애니메이션 실행"); } //이벤트를 발생시킨다 this.OnAnimationCompleteHandler(EventArgs.Empty); } //2. protected 와 virtual 키워드를 사용해서 메서드를 만든다 protected virtual void OnAnimationCom.. json저장, 불러오기 App using System; using System.IO; using Newtonsoft.Json; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace HelloWorld { class App { //생성자 public App() { //7. 파일 불러오기 string infoPath = "./weapon_info.json"; //4. 파일 읽기 string path = "./weapon_data.json"; string json = File.ReadAllText(path); Dictionary dicWeaponDatas = new Dictionary().. 파일 읽기, 역직렬화 연습 2 using System; using System.IO; //using 지시문으로 네임스페이스 추가 using Newtonsoft.Json; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace HelloWorld { class App { //생성자 public App() { //1. json파일 변수에 넣고 파일의 문자들을 읽어들여서 변수에 넣기 //2. 역직렬화 하기 (배열. JsonConvert.DeserializeObject(json값) //3. 배열의 요소들을 Dictionary에 추가하기 (foreach문 사용) //4. Dictionary에 잘 추가.. 파일 읽기, 역직렬화 연습 using System; using System.IO; //using 지시문으로 네임스페이스 추가 using Newtonsoft.Json; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace HelloWorld { class App { //생성자 public App() { string path = "./budget_data.json"; string json = File.ReadAllText(path); Console.WriteLine(json); //역직렬화 하기 BudgetData[] budgetDatas = JsonConvert.DeserializeObj.. 람다식 연습 15 (Comparision) using System; using System.Collections.Generic; //제너릭 컬렉션 사용전 선언 using System.Linq; using System.Text; using System.Threading.Tasks; namespace HelloWorld { class App { //생성자 public App() { Player player0 = new Player("홍길동", 32000); Player player1 = new Player("임꺽정", 600); Player player2 = new Player("김길동", 2700); Player player3 = new Player("장길산", 48900); Player player4 = new Player("홍길산", 1200).. 람다식 연습 8 (Action) using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace HelloWorld { class App { //생성자 public App() { Button btn = new Button(); btn.onClick = () => { Console.WriteLine("click!"); }; btn.Click(); } } } using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace .. 람다식 연습 7 (Func) - 피자 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace HelloWorld { class App { //생성자 public App() { Func func = (name) => { return new Pizza(name); }; Pizza pizze = func("페페로니피자"); Console.WriteLine(pizze.name); } } } using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.. 람다식 연습 6 (Func) 난수생성 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace HelloWorld { class App { //생성자 public App() { Random rand = new Random(); Func getRandNum = (a, b) => { return rand.Next(a, b); }; int randNum = getRandNum(1, 100); Console.WriteLine(randNum); //1 ~ 100사이 랜덤 숫자 (정수) } } } 람다식 연습 5 (Func) 두 수 더하기 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace HelloWorld { class App { //생성자 public App() { Func add = this.Sum; int result = add(10, 11); Console.WriteLine(result); } int Sum(int a, int b) { return a + b; } } } 람다식 연습 4 (Func) 장검 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace HelloWorld { class App { //생성자 public App() { FunccreateItem = (name) => { return new Item(name); }; Item item = createItem("장검"); Console.WriteLine("=> {0}", item.name); } } } using System; using System.Collections.Generic; using System.Linq; using System.Text; using Sys.. 이전 1 2 3 4 5 ··· 8 다음