반응형
c# -- 객체 이니셜라이저 (object initializer)
참고 ; https://www.c-sharpcorner.com/UploadFile/mahesh/object-initializer-in-C-Sharp/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 기존 방식 | |
Pen pen = new Pen(c, sPen.Width); | |
pen.DashStyle = sPen.DashStyle; | |
pen.StartCap = sPen.StartCap; | |
pen.EndCap = sPen.EndCap; | |
// object initializer 사용후 간결해짐. | |
Pen pen = new Pen(c, sPen.Width) { DashStyle = sPen.DashStyle, StartCap = sPen.StartCap, EndCap = sPen.EndCap }; | |
반응형
'C#' 카테고리의 다른 글
C# -- DataGridView 정렬과 row 이동하기 (DataTable, DataView 사용) (0) | 2019.04.27 |
---|---|
C# -- 현재 시간 구하기 & 시분초 시간을 초로 환산하기 (0) | 2019.04.11 |
C# -- comboBox 이미지 item 그리기 (0) | 2019.03.26 |
c# -- ColorDialog 사용하기, label 글자 크기 변경하기 (0) | 2019.03.25 |
C# -- property (속성) 사용법 (0) | 2019.03.16 |