C#的資料類型(Data types)主要分為兩個,一個是基本資料型態(Primitive Type),另外一個是參考資料型態(Reference Data Type)。不一樣的資料型態,所呈現的方式也會有所不同。
| Short Name | Width | Range (bits) |
|---|---|---|
| byte | 8 | 0 to 255 |
| sbyte | 8 | -128 to 127 |
| short | 16 | -32,768 to 32,767 |
| ushort | 16 | 0 to 65535 |
| int | 32 | -2,147,483,648 to 2,147,483,647 |
| uint | 32 | 0 to 4294967295 |
| long | 64 | -9223372036854775808 to 9223372036854775807 |
| ulong | 64 | 0 to 18446744073709551615 |
| Short Name | Width | Range (bits) |
|---|---|---|
| float | 32 | -3.402823e38 to 3.402823e38 |
| double | 64 | -1.79769313486232e308 to 1.79769313486232e308 |
| decimal | 128 | ±1.0 × 10e−28 to ±7.9 × 10e28 |
| Short Name | Width | Range (bits) |
|---|---|---|
| char | 16 | Unicode symbols used in text |
| Short Name | Width | Range (bits) |
|---|---|---|
| bool | 8 | True or false |
總結:如需進行轉換,比起明確轉換選擇隱含轉換,才不用承擔遺失資訊的風險。
※以上資料如有錯誤請多指教
書名:程式設計基本功與實務範例解析:使用C#(第三版)(附範例光碟)
Value Types and Reference Types