전체 글
07.Exception(예외처리)
using System; using System.Collections.Generic; namespace Csharp { class Program { static void Main(string[] args) { int a = 10; int b = 0; int result = a / b; try { // 1. 0으로 나눌 때 // 2. 잘못 된 메모리를 참조 (null) // 3. 너무 많은 용량을 복사 (오버플로우) } catch(Exception e) { } } } } using System; using System.Collections.Generic; namespace Csharp { class Program { static void Main(string[] args) { try { // 1. 0으로 ..
06.Lambda(람다)
using System; using System.Collections.Generic; namespace Csharp { // Lambda : 일회용 함수를 만드는데 사용하는 문법. enum ItemType { Weapon, Armor, Amulet, Ring } enum Rarity { Normal, Uncommon, Rare } class Item { //아이템 종류 public ItemType ItemType; //아이템 희귀도 public Rarity Rarity; } class Program { static List _items = new List(); //하드코딩 static Item FindWeapon() { foreach(Item item in _items) { //아이템들 중에서 Weapo..
05.event(이벤트)
event(이벤트)는 delegate(델리게이트)의 개선 버전이다. 그러므로 delegate(델리게이트) 코드 부터 보도록 한다. using System; using System.Collections.Generic; namespace Csharp { // delegate(델리게이트) : 함수 자체를 넘겨주는 방식. 형식의 이름을 내 맘대로..! (int float이 아니라 france) class Program { //int France()는 함수가 아니라 형식이다(ex : void나 int처럼) delegate int France(); //이 코드를 4개의 부분으로 자르면, // 1. delegate : 형식은 형식인데, 함수 자체를 인자로 넘겨주는 그런 형식 // 2. 반환 : int // 3. 입력..