Notice
Recent Posts
Recent Comments
Link
관리 메뉴

nomad-programmer

[Programming/C#] CTS (Common Type System) 본문

Programming/C#

[Programming/C#] CTS (Common Type System)

scii 2020. 9. 6. 15:24

공용 형식 시스템의 형식

클래스 이름 C# 형식 C++ 형식 VB 형식
System.Byte byte unsigned char Byte
System.SByte sbyte char SByte
System.Int16 short short Short
System.Int32 int int 또는 long Integer
System.Int64 long __int64 Long
System.UInt16 ushort unsigned short UShort
System.UInt32 uint unsigned int 또는 unsigned long UInteger
System.Uint64 ulong unsigned __int64 ULong
System.Single float float Single
System.Double
double double Double
System.Boolean
bool bool Boolean
System.Char
char wchar_t Char
System.Decimal
decimal Decimal Decimal
System.IntPtr
없음 없음 없음
System.UIntPtr
없음 없음 없음
System.Object
object Object* Object
System.String
string String* String

 

공용 형식 시스템의 형식은 각 언어에서 코드에 그대로 사용할 수 있다. 물론 C#도 가능하다.

using System;

namespace CSharpExam
{
    class CTSTable
    {
        static int Main(string[] args)
        {
            System.Int32 a = 123;
            int b = 456;

            System.Single c = 3.14f;
            float d = 3.14f;

            System.String str1 = "abc";
            string str2 = "abc";

            Console.WriteLine("type: {0}, value: {1}", a.GetType().ToString(), a);
            Console.WriteLine("type: {0}, value: {1}", b.GetType().ToString(), b);

            Console.WriteLine("type: {0}, value: {1}", c.GetType().ToString(), c);
            Console.WriteLine("type: {0}, value: {1}", d.GetType().ToString(), d);

            Console.WriteLine("type: {0}, value: {1}", str1.GetType().ToString(), str1);
            Console.WriteLine("type: {0}, value: {1}", str2.GetType().ToString(), str2);

            return 0;
        }
    }
}

/* 결과

type: System.Int32, value: 123
type: System.Int32, value: 456
type: System.Single, value: 3.14
type: System.Single, value: 3.14
type: System.String, value: abc
type: System.String, value: abc

*/
Comments