전체 글(164)
-
0326 쿠키런 직렬화/역직렬화
public class App { public App() { GameInfo gameInfo = null; string dataPath = "./cookie_data.json"; string infoPath = "./game_info.json"; //json 파일 읽기 string json = File.ReadAllText(dataPath); Console.WriteLine(json); //역직렬화 CookieData[] cookies = JsonConvert.DeserializeObject(json); //사전에 넣기 Dictionary dicCookies = cookies.ToDictionary(x => x.id); //파일이 있는지 검사 (신규 유저 판별) if (File.Exists(infoPat..
2021.03.26 -
0325 싱글턴 패턴
디자인 패턴은 하나의 클래스가 단지 하나의 인스턴스만 갖도록 제한한다. 전역 범위에서 그 인스턴스를 엑세스할 수 있게 하는 패턴이다. 일반적으로 singleton 인스턴스는 클라이언트가 처음 singleton 인스턴스를 엑세스할 때 생성된다. 구현: 생성자를 private Singleton 외부 클래스가 사용할 수 없도록 대신 필드는 public public class DataManager { private static DataManager instance; public Dictionary dicBlackCloudData; //생성자 private DataManager() { } public static DataManager GetInstance() { if (DataManager.instance == ..
2021.03.25 -
0324 File 클래스 (외부 파일 불러오기)
public class App { public App() { string text=File.ReadAllText("./helloworld.txt"); Console.WriteLine(text); } } (@"절대 경로 주소") ("./현재 경로 주소 파일.exe ") 직렬화 > 객체를 컴퓨터 언어로 101010 언어로 변경 JASON > 키+값 쌍으로 이루어진 데이터 포맷 shancarter.github.io/mr-data-converter/ Mr. Data Converter shancarter.github.io 위 사이트에서 엑셀 내용을 jason화 시키고 내용 그대로 복사, jsonviewer.stack.hu/ Online JSON Viewer jsonviewer.stack.hu 위 사이트에서 내용 ..
2021.03.24 -
0324 복습
public delegate void DelPrint(string message); public class Printer { public Printer() { } public void Print(string msg) { Console.WriteLine(msg); } } public class App { public App() { string message = "동해물과 백두산이..."; //객체 생성 Printer printer = new Printer(); //대리자 인스턴스 화 DelPrint delPrinter = new DelPrint(printer.Print); delPrinter(message); DelPrint delPrinter2 = delegate (string msg) { Console..
2021.03.24 -
0323 대리자를 이용해 다중 메서드 호출 Multicast delegate/delegate chaining
public class CarDriver { public CarDriver() { } public static void GoLeft() { Console.WriteLine("GoLeft"); } public static void GoFoward() { Console.WriteLine("GoFoward"); } } public class App { //대리자 선언 public delegate void GoHome(); public delegate void Say(); public App() { //대리자 변수 선언 및 초기화 GoHome go = new GoHome(CarDriver.GoLeft); //대리자 객체 추가 go += new GoHome(CarDriver.GoFoward); go -= new ..
2021.03.23 -
0323 익명 함수
메서드를 매개 변수로 전달할 수 있다. 람다 식을 사용한다. 람다 식 => 람다 선언 연산자를 사용하여 본문에서 람다의 매개 변수 목록을 구분 식에 {} 붙어있으면 문 람다 ; 대리자+익명함수(lambda) public App() { Console.WriteLine("App"); Action sayHello = this.SayHello; Action sayhello = () => { Console.WriteLine("Hello Word "); }; //대리자 초기화 Action SendMessage = this.SendMessage; Action sendMessage = (message) => { Console.WriteLine(message); }; //대리자 호출 sendMessage("안녕하세요")..
2021.03.23