반응형

C#/문제해결 38

0327 _ Callback 구조 파악

1. BookDB 안에 있는 ProcessBooks 메서드에 들어갑니다. 2. ProcessBooks 메서드에 1 의 값이들 먼저 들어온다. foreach 문에서 book으로 list의 값들이 들어간다. 그리고 그 book의 변수를 callback 변수로 받아서 다시 1번의 변수로 콜백을 한다. 3. 첫 메서드에서 사용한 PrintTitle의 메서드의 변수로 2번째 값이 들어간다. 그 변수를 사용하여 출력을 한다. 4. 최종적으로 PrintTitle의 기능이 출력이 된다.

C#/문제해결 2021.03.27

0327_개체 참조가 개체의 인스턴스로 설정되지 않았습니다.

------ 개체 참조가 개체의 인스턴스로 설정되지 않았습니다. 오류는 대부분 참조하려는 객체가 인스턴스 (new) 가 되지 않은 경우가 많다. 위와 같은 상황에서도 BookDB 클래스의 리스트에 book를 넣고, 컴파일을 시도했지만, 오류가 떴다. 이 오류는 list를 변수로 선언만하고, 인스턴스화를 시켜주지 않아서 생기는 오류이다. 위와 같이 생성자 안에 list의 인스턴스르 만들어 주면 된다.

C#/문제해결 2021.03.27

0325_ (미해결)동일한 키를 사용하는 항목이 이미 추가되었습니다.

using Newtonsoft.Json; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace study10 { public class App { public App() { string json = File.ReadAllText("./card_data.json"); var arr = JsonConvert.DeserializeObject(json); var dic = arr.ToDictionary(x => x.id); foreach (var pair in dic) { var data = pair.Value;..

C#/문제해결 2021.03.26

0317_ 인벤토리_개체 참조가 개체의 인스턴스로 설정되지 않았습니다.

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace study05_HW { public class Inventory { public int capacity; public Item[] items; public int index; public Inventory(int capacity) { this.capacity = capacity; this.items = new Item[this.capacity]; } public void Additem(Item item) { this.items[this.index] = item; Console.Wri..

C#/문제해결 2021.03.18

0317_인벤토리만들기, 인덱스가 배열 범위를 벗어났습니다.

new Inventory(3); 를 넣었지만, public Inventory(int capacity){ this.items = new Item[this.capacity]; } 에 this.capacity = capacity; 가 빠져서, 커퍼시티 변수가 맴버변수에 들어가지 않아서 인덱스 값이 생성되지 않아서 생긴 오류 였습니다. public Inventory(int capacity){ this.capacity = capacity; this.items = new Item[this.capacity]; } 으로 수정하였습니다.

C#/문제해결 2021.03.18
반응형