データ型

C# のプリミティブ データ型はいずれも System 名前空間のオブジェクトです。
各データ型には、短い名前 (エイリアス) が与えられます。

C# では、すべてのプリミティブ データ型がオブジェクトとして表現されるので、プリミティブ データ型でオブジェクト メソッドを呼び出すことができます。

基本データ型

予約語
(短い名前)
.NET クラス データ型
(Bit)
数値範囲
sbyte System.SByte 符号付き整数 8 -128 ~ 127
byte System.Byte 符号なし整数 8 0 ~ 255
short System.Int16 符号付き整数 16 -32768 ~ 32767
ushort System.UInt16 符号なし整数 16 0 ~ 65535
int System.Int32 符号付き整数 32 -2147483648 ~ 2147483647
uint System.UInt32 符号なし整数 32 0 ~ 4294967295
long System.Int64 符号付き整数 64 -922337203685477508 ~
922337203685477507
ulong System.UInt64 符号なし整数 64 0 ~ 18446744073709551615
float System.Single 単精度浮動小数点型 32 -3.402823e38 ~ 3.402823e38
double System.Double 倍精度浮動小数点型 64 -1.79769313486232e308 ~
1.79769313486232e308
char System.Char 単一 Unicode 文字 16 テキストで使用される Unicode 記号
bool System.Boolean 論理ブール型 8 true または false
string System.String 文字列
decimal System.Decimal 10 進数型 128 ±1.0 × 10e − 28 ~ ±7.9 × 10e28
29 の有効桁数で 10 進数を
正確に表現可能な小数または整数型

プリミティブ データ型でオブジェクトメソッドの呼び出し

// プリミティブ データ型でオブジェクトメソッドの呼び出し program in C#.
static void Main()
{    
    int i = 100;
    string s = i.ToString("0000");    
    Console.WriteLine("i={0},s={1}", i.ToString(), s);
}

実行結果

i=100,s=0100


Last updated:2017/05/07
Author:efn

';