반응형

C# 51

C# DateTime Now에서 날짜만 가져 오기

DateTime.Now 하면 현재 날짜와 시간을 얻어 올 수 있다. (년 월 일 시간 분 초 ) 이 중에 시간은 0(자정)으로 초기화 시키고 날짜만 얻어 오고 싶으면 아래 예제 처럼 DateTime변수.Date 함수를 사용 하면 된다. using System; public class Example { public static void Main() { DateTime date1 = new DateTime(2008, 6, 1, 7, 47, 0); Console.WriteLine(date1.ToString()); // Get date-only portion of date, without its time. DateTime dateOnly = date1.Date; // Display date using short..

Programming 2020.07.17

C# List 배열 회전 시키기 - Right Rotation - Unity3D

C# List - Right Rotation - Unity3D 간혹 List 를 사용 하다가 환영큐 처럼 특정 요소 이후로 모든 요소를 재배치 시킬 일이 있다. 예) 1 2 3 4 5 -> Rotate in place (3) -> 3 4 5 1 2 이럴때 다음의 Extension Method를 사용 하면 된다. public static void Rotate(this List src, T item) { int index = src.LastIndexOf(item); src.Rotate(index); } public static void Rotate(this List src, int index) { int count = src.Count - index; for (; count > 0; count--) { T ..

Programming 2020.03.27

C# - Enum 형의 내부 형식 변경과 유용한 메소드 - byte

1. Enum 타입의 내부 기본 타입 변경 Enum 변수를 선언 할 때 기본적으로 데이터 형이 Int32 형으로 선언 된다. 메모리 사용을 조금이라도 줄일기 위해서 숫자가 크지 않는 경우에는 byte를 사용 하고 싶을 때가 있다. Enum 형의 기본 데이터 형을 변경 하려면 다음과 같이 하면 된다. public enum Days : byte { Saturday, Sunday, Monday, Tuesday, Wednesday, Thursday, Friday }; 2. Enum 타입의 내부 기본 타입 얻기 Enum.GetUnderlyingType(enumType); static void DisplayEnumInfo(Enum enumValue) { Type enumType = enumValue.GetType(..

Programming 2020.03.13
반응형