お遍路さんのプログラム言語備忘録

定数・変数の定義

VisualC#定数・変数の定義

確認環境 Microsoft Visual Studio Community 2019 Version 16.4.4 .NET Core 3.1
.NET型 サフィックス サイズ 符号 最小値 範囲 最大値
sbyte System.SByte 1バイト 付き -128 127
byte System.Byte 1バイト なし 0 255
short System.Int16 2バイト 付き -32,768 32,767
ushort System.UInt16 2バイト なし 0 65,535
int System.Int32 4バイト 付き -2,147,483,648 2,147,483,647
uint System.UInt32 無,u,U 4バイト なし 0 4,294,967,295
long System.Int64 無,l,L 8バイト 付き -9,223,372,036,854,775,808 9,223,372,036,854,775,807
ulong System.UInt64 無,u,U,l,L, UL,Ul,uL,ul, LU,Lu,lU,lu 8バイト なし 0 18,446,744,073,709,551,615
検証
Console.WriteLine(string.Format("{0}:{1}byte:{2}~{3}","sbyte ", System.Runtime.InteropServices.Marshal.SizeOf(typeof(sbyte)), System.SByte.MinValue, System.SByte.MaxValue));
Console.WriteLine(string.Format("{0}:{1}byte:{2}~{3}","byte  ", System.Runtime.InteropServices.Marshal.SizeOf(typeof(byte)),System.Byte.MinValue, System.Byte.MaxValue));
Console.WriteLine(string.Format("{0}:{1}byte:{2}~{3}","short ", System.Runtime.InteropServices.Marshal.SizeOf(typeof(Int16)),System.Int16.MinValue, System.Int16.MaxValue));
Console.WriteLine(string.Format("{0}:{1}byte:{2}~{3}","ushort", System.Runtime.InteropServices.Marshal.SizeOf(typeof(UInt16)),System.UInt16.MinValue, System.UInt16.MaxValue));
Console.WriteLine(string.Format("{0}:{1}byte:{2}~{3}","int   ", System.Runtime.InteropServices.Marshal.SizeOf(typeof(Int32)),System.Int32.MinValue, System.Int32.MaxValue));
Console.WriteLine(string.Format("{0}:{1}byte:{2}~{3}","uint  ", System.Runtime.InteropServices.Marshal.SizeOf(typeof(UInt32)),System.UInt32.MinValue, System.UInt32.MaxValue));
Console.WriteLine(string.Format("{0}:{1}byte:{2}~{3}","long  ", System.Runtime.InteropServices.Marshal.SizeOf(typeof(Int64)),System.Int64.MinValue, System.Int64.MaxValue));
Console.WriteLine(string.Format("{0}:{1}byte:{2}~{3}","ulong ", System.Runtime.InteropServices.Marshal.SizeOf(typeof(UInt64)),System.UInt64.MinValue, System.UInt64.MaxValue));
.NET型 サフィックス 精度 サイズ 小数点以下精度 範囲 最小値・最大値
float System.Single f,F 7桁 4バイト ±1.5e−45 ±3.4e38
double System.Double 無,d,D 15桁 8バイト ±5.0e−324 ±1.7e308
decimal System.Decimal m,M 28桁 16バイト ±1.0e-28 ±7.9228e28
検証
Console.WriteLine(string.Format("{0}:{1}byte:{2}~{3}","single ", System.Runtime.InteropServices.Marshal.SizeOf(typeof(float)),float.MinValue, float.MaxValue));
Console.WriteLine(string.Format("{0}:{1}byte:{2}~{3}","double ",  System.Runtime.InteropServices.Marshal.SizeOf(typeof(double)),double.MinValue, double.MaxValue));
Console.WriteLine(string.Format("{0}:{1}byte:{2}~{3}","decimal", System.Runtime.InteropServices.Marshal.SizeOf(typeof(decimal)),decimal.MinValue, decimal.MaxValue));
.NET型
void*, int*等 System.IntPtr ポインタ(符号付き) ポインターまたはハンドルを表すときに使用されるプラットフォーム固有の型
void*, int*等 System.UIntPtr ポインタ(符号なし) ポインターまたはハンドルを表すときに使用されるプラットフォーム固有の型。
BigInteger System.Numerics.BigInteger 多倍長整数型符号付き整数 扱う値の大きさに合わせて格納領域の割り当てが行われるため扱える値に理論上の上限がない
Complex System.Numerics.Complex 複素数 実数部と虚数部で構成される数値
.NET型 サフィックス サイズ 最小値 範囲 最大値
char System.Char '(シングルコーテーション) 16ビット U+0000 U+FFFF
エスケープシーケンス 文字名 Unicode
\' 単一引用符文字リテラル('') 中に 'を書くために使う 0x0027
\" 二重引用符文字列リテラル("") 中に "を書くために使う 0x0022
\\ 円記号 0x005C
\0 Null 0x0000
\a アラート 0x0007
\b バックスペース 0x0008
\f フォーム フィード 0x000C
\n 改行 0x000A
\r キャリッジ リターン行頭に戻る処理 0x000D
\t 水平タブ 0x0009
\v 垂直タブ 0x000B
\u Unicodeの文字コード(\Uの頭4桁0省略) \u0061
\U Unicodeの文字コード(8桁) \U00000061
\x Unicodeの文字コード(\uの頭0省略) \x61
.NET型 サフィックス サイズ
string System.String "(ダブルコーテーション) 2GBまたは約10億文字
page top