목록C++ & C#/C# (6)
오보에블로그
Comparision 정렬 메소드중 오버로드 된것중에 하나로는 List.Sort(Comparision) 가 있다. Comparision 는 delegate 로 정의된 대리자로, delegate int Comparison(T x, T y); 로 Comparison에는 x 와 y를 받아서 x가 y 보다 작으면 0보다 작은 정수를, x 와 y가 같으면 0을, x가 y 보다 크면 1 을 리턴해야하는 함수를 할당해야한다. 이걸 쓰면 크고 작음의 기준을 커스텀하게 작성할 수 있어서 편리하다. 예시 public string[] solution(string[] strings, int n) { List stringList = new List(); stringList.AddRange(strings); stringList...
Count Count(IEnumerable, Func) 해당 람다식에서 true를 반환하는 원소만 센다. 예시 List numbers = new List() {1,2,3,4,5,6,7,8}; int answer = numbers.Count( x => { if (x % 2 == 1) return true; else return false; } ); Select 해당 열거자에대해 다른 포맷으로 변경 예시 int[] numbers = {1,2,3,4,5,6,7 }; IEnumerable query = numbers.Select((number, index) => { if (number % 2 == 0) return number; else return -1; }); IEnumerable squares = Enum..
IEnumerator와 IEnumerable 사용 목적은 아래 링크를 참고한다. IEnmerator 인터페이스 설명 public interface IEnumerator { // Enumerator의 열거자에서 현재 바라보고 있는 위치를 반환 object? Current { get; } // 열거자에서 다음 element로 이동하는 함수 bool MoveNext(); // 열거자에서 현재 바라보고 있는 위치를 초기로 변환 void Reset(); } IEnumerable 인터페이스 설명 public interface IEnumerable { // 열거자에 대한 Enumerator 반환 IEnumerator GetEnumerator(); } IEnumerator , IEnumerable 이용 예시 class..
API 링크 참고 StirngBuilder string 에 짧은 시간동안 이어 붙이면 동적할당이 빈번하게 일어나서 성능이 저하 될 수 있다. StringBuilder은 변경 가능한 문자열 class이다. 사용 예시 static StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append(result[i] + 1 + " ");
https://social.msdn.microsoft.com/Forums/vstudio/en-US/8c5c792f-d17d-443c-8098-76797aafd588/algorithm-the-longest-common-substring-of-two-strings?forum=csharpgeneral Algorithm the longest common substring of two strings Well, if you want a good algorithm, you can find it in Wikipedia: https://en.wikipedia.org/wiki/Longest_common_substring_problem The algorithm there is written in pseudo-code, bu..
try , catch 구문에서 try에 다른 프로그램을 실행시킬때, error를 catch 하지 못할때가 있습니다. (설령 catch 한다고 하더라도 프로그램이 끝난후에야 catch 될 때) 그럴 때는 비동기 thread인 task를 이용하고 아주 멋지신 분이 정리 해놓은 코드를 사용하도록 합시다. https://pastebin.com/K8MWQuJ6 [C#] Task with timeout - Pastebin.com Not a member of Pastebin yet? Sign Up, it unlocks many cool features! class Program { static void Main(string[] args) { var program = new Program(); program.Test(..