概要
128bitの整数(Int128・UInt128)が.NET7から導入されました。C#のバージョン的にはC# 11からのタイミングなはずです。
C# 言語のバージョン管理 - C# ガイド - C# | Microsoft Learn
Int128 maxInt128 = Int128.MaxValue; Int128 minInt128 = Int128.MinValue; // 170141183460469231731687303715884105727 Console.WriteLine(maxInt128); // -170141183460469231731687303715884105728 Console.WriteLine(minInt128); UInt128 maxUInt128 = UInt128.MaxValue; UInt128 minUInt128 = UInt128.MinValue; // 340282366920938463463374607431768211455 Console.WriteLine(maxUInt128); // 0 Console.WriteLine(minUInt128);
C#の場合は、それぞれの型は以下のような関係性になっています。
| 型 | バイト数 |
|---|---|
| sizeof(sbyte) | 1byte = 8bit |
| sizeof(byte) | 1byte = 8bit |
| sizeof(short) | 2byte = 16bit |
| sizeof(ushort) | 2byte = 16bit |
| sizeof(int) | 4byte = 32bit |
| sizeof(uint) | 4byte = 32bit |
| sizeof(long) | 8byte = 64bit |
| sizeof(ulong) | 8byte = 64bit |
つまりはInt128・UInt128はlong・ulongの2倍のバイト数というわけですね。