반응형 분류 전체보기505 백준 C# 27866 String 메서드 알아보러 가기 C# - String (찾기, 변형, 분할, 제거 메서드) 1. 찾기 01 Contains 특정 문자열이 문자열안에 있는지 확인 public bool Contains (string value); 반환 Boolean : 문자열이 있으면 true 없으면 false 를 반환한다. string name = "Pink Pig"; bool found = name.Contains("Pink"); Con code-piggy.tistory.com using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace baek2 { class Program { static void Main.. 2023. 4. 21. 백준 C# 1546 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. 21. C# 문법 - Nullable type Nullable -> Null + able (null이 가능한) 1. 선언 및 할당 방법 Nullable 변수명 T? 변수명 int? number = null; 2. 속성 01 HasValue 내부 형식의 올바른 값이 있는지 여부를 나타내는 값을 가져온다 public bool HasValue { get; } 현재 개체에 값이 있으면 true, 없으면 fasle if(number.HasValue) { } 02 Value 현재 Nullable의 값을 가져온다 public T Value { get; } int? number = null; int a = number.Value; Hasvalue 속성이 fasle이면 예외가 throw된다. int? number = 3; int a = number.Value; Ha.. 2023. 4. 20. C# 문법 - Reflection, Attribute 1. Reflection class의 모든 필드의 정보를 가져오는 X-ray와 같은 기능을 가지고 있다. C#에서 모든 객체들은 오브젝트 객체에서 파생되어 나온 것이다. Pig클래스에서 없는 함수가 pig 객체에서 나오는 것을 확인 할 수 있다. 이는 오브젝트 클래스에서 선언된 함수들이다. 01 GetType 객체의 데이터타입을 반환 public Type GetType (); Type type = pig.GetType(); 02 GetFields(BindingFlags) 현재 Type에 대해 정의된 필드를 지정된 binging 조건으로 검색 public abstract System.Reflection.FieldInfo[] GetFields (System.Reflection.BindingFlags bind.. 2023. 4. 20. C# 문법 - exception 1. exception 예기치 못한 예외적인 것을 처리 (예를 들어 0으로 나눌때, 잘못된 메모리를 참조, 오버플로우 등이 있다.) 2. try - catch try - 예외가 발생 되었을 시 catch문으로 catch - 예외 발생시 처리하는 부분 try { } catch(Exception e) { } 0으로 나눌 경우 예외가 처리되어있지 않다고 오류가 뜨면서 프로그램이 종료된다. int a = 10; int b = 0; int result = a / b; try- catch문을 사용할 경우 try { int a = 10; int b = 0; int result = a/b; } catch (Exception e) { } Exception 모든 예외사항의 조상님 원하는 예외는 따로 처리하고 싶은 경우 예.. 2023. 4. 19. C# 문법 - Lambda, Func, Action Lambda 일회용 함수를 만든느 데 사용하는 문법 1. Lambda를 사용하는 이유 함수의 용도에 따라 아래와 같이 하나하나 늘리는 것은 매우 비효율적인 방법이다. static Item FindWeapon() { foreach (Item item in _items) { if (item.ItemType == ItemType.Weapon) return item; } return null; } static Item FindRareItem() { foreach (Item item in _items) { if (item.Rarity == Rarity.Rare) return item; } return null; } 이를 효율적인 방법으로 바꾸기위해 delegate를 사용한다. item을 인자로 받아서 Item이 .. 2023. 4. 19. 이전 1 ··· 69 70 71 72 73 74 75 ··· 85 다음 반응형