본문 바로가기

C#7

[C#] Stopwatch를 사용하여 작업 속도 측정 업무 중에 속도 개선해야 할 일이 있어서 측정을 위해 테스트 코드로 작성해봤다. using System.Diagnostics; Stopwatch sw = new Stopwatch(); sw.Start(); // Do Something sw.Stop(); Console.Write(sw.ElapsedMilliseconds.ToString() + "ms"); 2021. 11. 22.
[C#][.Net WinForm] DateTimePicker 디버그 중 프로그램 응답 없음 VS2010에서 WinForm 프로그램 개발중 DateTimePicker의 ValueChanged 이벤트에 중단점을 걸었는데.. Hit하면 VS와 WinFormApp 둘 다 응답없음이 뜨는 이슈를 겪었다. https://developercommunity.visualstudio.com/t/debugger-crashes-on-datetimechanged-event/218801 Debugger crashes on DateTimeChanged event The strange thing is that VS crashes/becomes unresponsive before you can do anything in the debugger. So VS stops at the breakpoint and waits for .. 2021. 6. 2.
[C#] XML Convert to CSV XmlDocument 클래스 사용해서 Xml Parsing을 해보자. 아래의 Xml 문서는 w3school에 예제로 있는 자료인데 직접 만들기 귀찮으니 활용했다. Belgian Waffles $5.95 Two of our famous Belgian Waffles with plenty of real maple syrup 650 Strawberry Belgian Waffles $7.95 Light Belgian waffles covered with strawberries and whipped cream 900 Berry-Berry Belgian Waffles $8.95 Belgian waffles covered with assorted fresh berries and whipped cream 900 Fren.. 2021. 3. 13.
[C#] MDI (Multiple Document Interface) MDI : SDI와는 달리 폼 안에 여러 Child Form을 가지는 형태. - C# 에서는 MdiParent를 통해 Parent Form과 Child Form을 연결하는 메서드를 지원한다. MDI 자식 양식 정렬 - LayoutMdi 메서드의 인수로 MdiLayout 열거형 값을 사용하여 MDI 부모 폼에서 자식 폼을 정렬할 수 있다. - 계단식 정렬 (MdiLayout.Cascade) - 수평 정렬 (MdiLayout.TileHorizontal) - 수직 정렬 (MdiLayout.TileVertical) 코드 - Form1.cs (MDI 부모 폼) using System; using System.Collections.Generic; using System.ComponentModel; using Sys.. 2021. 3. 13.
[C#] 리플렉션(Reflection), 애트리뷰트(Attribute) 리플렉션 (Reflection) : 런타임에 클래스나 객체의 타입 정보를 조사하는 기능 - 보통 컴파일러에 의해 기계어로 바뀌고 나면 사라지지만, C#은 컴파일된 결과 코드뿐만 아니라 타입에 대한 메타 데이터를 실행 파일에 같이 기록해놓기 때문에 실행 중에도 정보를 조사할 수 있다. - 루트 클래스인 Object에 있는 GetType() 메서드를 통해 얻은 Type 객체를 통해 수행이 가능하다. Type 객체를 얻는 방법 1. 루트 클래스인 Object의 GetType 메서드를 호출한다. - 정적 메서드가 아니므로 객체가 있어야 호출 가능하다. 객체.GetType() 2. Type의 정적 메서드인 GetType 메서드를 호출한다. - 클래스 이름(문자열)으로 정보를 조사하므로 객체가 없어도 호출이 가능하.. 2021. 3. 4.
[C#] 프로퍼티(Property), 익명 타입 1. 프로퍼티(Property) 자바에서 Getter Setter 를 사용할 때 클래스의 멤버 변수가 많아질 때마다 코드가 길어지는 불편함이 있었다. C#에서의 프로퍼티라는 메서드(?)도 필드(?)도 아닌 이 기능으로 정리하자면 이렇다. class Human { private string name; private int age; public string Name { get { return name; } set { name = value; } } public int Age { get { return age; } set { age = value; } } } 이를 조금 더 단순화 시켜서 이런 식으로 정의할 수 있다. 자동구현 프로퍼티 라고 한다. using System; namespace ConsoleAppl.. 2021. 1. 25.