c++數據類型大小受操作平台的影響,而在c#中,數據類型的定義都以與平台無關的方式定義,以備將來C#和.NET遷移到其他平台上。
這里說一下浮點類型在c#語言中的定義。
c#可以支持float ,double和decimal浮點數據類型。
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6 7 namespace ConsoleApplication1 8 { 9 class Program 10 { 11 static void Main(string[] args) 12 { 13 Console.WriteLine("sizeof float={0},double={1},decimal={2}",sizeof(float),sizeof(double),sizeof(decimal)); 14 Console.ReadKey(); 15 } 16 } 17 }
運行結果:
sizeof float=4,double=8,decimal=16