閱讀Stephens' C#教材第十一章筆記
Chapter 11 Using Variables and Performing Calculations.
Data Type |
Meaning |
Range |
byte |
Byte(8-bit記憶空間) |
0 to 255 |
sbyte |
Signed byte(8-bit記憶空間) |
-128 to 127 |
short |
Small signed integer(16-bit記憶空間) |
-32,768 to 32,767 |
ushort |
Unsigned short(16-bit記憶空間) |
0 to 65,535 |
int |
Integer(32-bit記憶空間) |
-2,147,483,648 to 2,147,483,647 |
uint |
Unsigned integer(32-bit記憶空間) |
0 to 4,294,967,295 |
long |
Long integer(64-bit記憶空間) |
-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 |
ulong |
Unsigned long(64-bit記憶空間) |
0 to 18,446,744,073,709,551,615 |
float |
Floating point(32-bit記憶空間) |
大約在 -3.4e38 to 3.4e38 之間 有效位數7位 |
double |
Big floating point(64-bit記憶空間) |
大約在 -1.8e308 to 1.8e308之間 有效位數15/16位 |
decimal |
Higher precision and smaller range then floating-point types(128-bit記憶空間) |
大約在 -7.9e28 to 7.9e28之間 有效位數28/29位 |
char |
Character(16-bit記憶空間) |
0 to 65,535 A single Unicode character. |
string |
Text(視字串長度不定) |
1 to 231 character |
bool |
Boolean |
Can be Ture or Flase |
object |
An objent |
Can point to almost anything. |
Seuence |
Meaning |
\a |
Bell(發出一聲) |
\b |
Backspace(倒退一格) |
\f |
Formfeed(跳至下一頁起點) |
\n |
Newline(插入新行) |
\r |
Carriage return(跳至同一行起點) |
\t |
Horizontal tab(水平方向的Tab鍵效果) |
\v |
Vertical tab(垂直方向的Tab鍵效果) |
\’ |
Single quotation mark(顯示單引號) |
\” |
Double quotation mark(顯示雙引號) |
\\ |
Backslash(顯示反斜線) |
\? |
Question mark(顯示問號) |
\ooo |
ASCII character in octal(八進位數字的ASCII編碼符號) |
\xhh |
ASCII character in hexadecimal(16進位數字的ASCII編碼符號) |
\xhhhh |
Unicode character in hexadecimal(16進位數字的Unicode編碼符號) |
// Convert from Celsius to Fahrenheit.
private void cToFButton_Click(object sender, EventArgs e)
{
float celcius = float.Parse(celsiusTextBox.Text);
float fahrenheit = celcius * 9 / 5 + 32;
fahrenheitTextBox.Text = fahrenheit.ToString();
}
// Convert from Fahrenheit to Celsius.
private void fToCButton_Click(object sender, EventArgs e)
{
float fahrenheit = float.Parse(fahrenheitTextBox.Text);
float celcius = (fahrenheit - 32) * 5 / 9;
celsiusTextBox.Text = celcius.ToString();
}
CurrencyConvertert程式示範各國幣值的換算