728x90
반응형
728x170
▶ Convert 클래스 : ChangeType 정적 메소드를 사용해 지정 타입으로 변환하기 예제
using System;
string a = "123";
Console.WriteLine("문자열 A : {0}", a);
int b = Convert(a, typeof(int));
Console.WriteLine("정수 B : {0}", b);
int c = b + 7;
Console.WriteLine("정수 C : {0}", c);
string d = Convert(c, typeof(string));
Console.WriteLine("문자열 D : {0}", d);
▶ Convert 클래스 : ChangeType 정적 메소드를 사용해 지정 타입으로 변환하기
#region 변환하기 - Convert(sourceValue, targetType)
/// <summary>
/// 변환하기
/// </summary>
/// <param name="sourceValue">소스 값</param>
/// <param name="targetType">타겟 타입</param>
/// <returns>변환 값</returns>
public dynamic Convert(dynamic sourceValue, Type targetType)
{
return System.Convert.ChangeType(sourceValue, targetType);
}
#endregion
728x90
반응형
그리드형(광고전용)
'C# > Common' 카테고리의 다른 글
[C#/COMMON] NTFS MFT를 사용해 디렉토리 크기 구하기 (0) | 2018.09.16 |
---|---|
[C#/COMMON] DirectoryInfo 클래스 : EnumerateDirectories 메소드를 사용해 디렉토리 크기 구하기 (0) | 2018.09.13 |
[C#/COMMON] DirectoryInfo 클래스 : EnumerateFiles 메소드를 사용해 디렉토리 크기 구하기 (0) | 2018.09.13 |
[C#/COMMON] FSO를 사용해 디렉토리 크기 구하기 (0) | 2018.09.13 |
[C#/COMMON] 우리나라 전통 색상 코드 (0) | 2018.09.08 |
[C#/COMMON] 애플리케이션 구성 파일 선택하기 (0) | 2018.08.22 |
[C#/COMMON] 애플리케이션 구성 파일 변경하기 (0) | 2018.08.22 |
[C#/COMMON] FTP 클라이언트 프로그램 만들기 (0) | 2018.08.21 |
[C#/COMMON] 부모 프로세스에서 자식 프로세스 표준 출력 수신하기 (0) | 2018.08.20 |
[C#/COMMON] PING 사용하기 (0) | 2018.06.11 |
댓글을 달아 주세요