전자기린
-
[C#] C#에서 Python 코드 사용하기 (함수, 클래스)Microsoft .NET/C# 2019. 4. 11. 18:18
C#에서 Python Code를 사용하기 위해서는 NuGet 패키지를 설치해야 합니다. IronPython 패키지를 설치합니다. def GetString(): return 'Hello World' def Sum( num1, num2 ): return num1 + num2 def GetList1(data): data.append('Python1') data.append('Python2') data.append('Python3') return data def GetList2(): data=[] data.append('Python1') data.append('Python2') data.append('Python3') return data class World: def __init__(self): self.na..
-
[C#] 널 결합 연산자 (Null Coalesce Operator)Microsoft .NET/C# 2019. 4. 10. 10:41
string str = null; (str ?? "비어있음.") ?? 좌측에 존재하는 변수(str)를 null과 비교(==)하여 true라면 ?? 우측의 값을 반환하고 false라면 변수(str)의 값을 반환한다. string str = null; //str의 값이 NULL이라면 "비어있음."을 반환한다. //1번 - Null Coalesce Operator (널 결합 연산자) MessageBox.Show((str ?? "비어있음.")); //2번 - 3항 연산자 사용 MessageBox.Show((str == null ? "비어있음." : str)); //3번 - if문 사용 if (str == null) str = "비어있음."; MessageBox.Show(str);
-
[C#] cm <-> pixel 변환, DPI 구하기Microsoft .NET/C# 2019. 4. 2. 10:30
DPI 활용 방향 디스플레이에 출력되는 물체의 크기가 실제 크기와 동일해야 하는 경우 DPI를 사용하여 CM를 PIXEL로 변환하여 출력 C#에서 DPI 구하기 public class ScreenInformations { public static uint RawDpi { get; private set; } static ScreenInformations() { uint dpiX; uint dpiY; GetDpi(DpiType.RAW, out dpiX, out dpiY); RawDpi = dpiX; } /// /// Returns the scaling of the given screen. /// /// The type of dpi that should be given back.. /// Gives the h..
-
[C#] 조건부 컴파일 기호, 여러 개(코드 비활성화, 코드 숨기기, #if, #else, #endif)Microsoft .NET/C# 2019. 3. 21. 18:30
사용 목적에 따라 특정 코드를 비활성화해야 되는 상황에는 #define과 #if, #else, #endif를 사용하여 처리하지만 다수의 CS에서 같은 처리를 하게 되면 매우 불편합니다. 그런 상황에서는 조건부 컴파일 기호와 #if, #else, #endif를 사용하면 됩니다. 1. 솔루션 우클릭 -> 속성 -> 빌드 여백을 추가하여 다수의 기호를 추가가능합니다. 2. 코드에 적용 #if A-TYPE //code A #else //code B #endif 위 이미지와 같이 해당 기호가 조건부 컴파일 기호인지 체크하여 해당 코드만 활성화합니다.
-
[C#] 폴더 경로 / Folder PathMicrosoft .NET/C# 2019. 3. 6. 01:35
폴더 경로 받기 Environment.CurrentDirectory Forms System.Windows.Forms.Application.StartupPath 실행파일폴더 System.AppDomain.CurrentDomain.BaseDirectory 실행된 exe의 경로 System.IO.Path.GetDirectoryName(System.IO.Path.GetDirectoryName(System.AppDomain.CurrentDomain.BaseDirectory)) "../" 상위폴더 Environment.SystemDirectory 시스템폴더 Path.GetFileName(Environment.CurrentDirectory) 현재 폴더의 명
-
[C#] 날짜 출력 형식 변경(영문) 및 시간 측정Microsoft .NET/C# 2019. 3. 5. 01:21
날짜 출력 형식 변경 //16-Jun-2021 string result0 = DateTime.Now.ToString("dd-MMM-yyyy", new System.Globalization.CultureInfo("en-US")); //hh = 12시간 기준 //HH = 24시간 시준 //2018-06-21 06:48:40.4868 string result1 = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss.ffff"); //18-06-21 06:48:57.7224 string result2 = DateTime.Now.ToString("yy-MM-dd hh:mm:ss.ffff"); //18년06월21일 06시49분49.8483초 string result3 = DateTime.N..