?? predefinedtypes.cs
字號:
using System;
class predefinedTypes
{
public static void Main()
{
string str = "this is a string."; //聲明一個字符串變量
Console.WriteLine(str); //打印出變量str
string strCopy = string.Copy(str); //把str的值賦給另一個字符串變量strCopy
Console.WriteLine(strCopy); //打印出變量strCopy
bool testbool = (str == strCopy); //判別str的值是否和strCopy的值是否相等,并把結果賦給邏輯變量testbool
Console.WriteLine(testbool); //打印出str和strCopy是否相等的邏輯結果
testbool = ((object)str == (object)strCopy); //判別str所指的對象是否和strCopy所指的對象相同,并把結果賦給邏輯變量testbool
Console.WriteLine(testbool); //打印出str所指對象和strCopy所指對象是否相同的邏輯結果
//float testfloat = 2323.03; //這樣寫是錯誤的,因為C#中默認的數值數據類型為double. 一定要在數字后加上F才行。長類型到短類型的轉換需要強制進行。
float testfloat = 2323.03F; //這樣寫才是正確的。
Console.WriteLine(testfloat); //打印出testfloat的值
double testdouble = 2323.03; //聲明一個double,并給它賦值
//double testdouble = 2323.03D; //這樣寫也行,更清晰
Console.WriteLine(testdouble); //打印出testdouble的值
testbool = ( testfloat == testdouble ); //判別testfloat和testdouble是否相等
Console.WriteLine(testbool); //這里的結果是False,同是2323.03,因為數據類型不同,存儲的長度也不同,其近似結果也不同,故不相等。
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -