卧底Int64
在C#中,初看int64也是和int16、int32具有一樣的int的基因,其實不然。int64作為一個資料類型并不屬于int,而是long派到int的卧底。欲知詳情,請看證據:
一、int16、int32和int65各自的範圍 Int16 值類型表示值介于 -32768 到 +32767 之間的有符号整數。
Int32 值類型表示值介于 -2,147,483,648 到 +2,147,483,647 之間的有符号整數。
Int64 值類型表示值介于 -9,223,372,036,854,775,808 到 +9,223,372,036,854,775,807 之間的整數。
二、short、int和long的愛恨糾纏
從上圖不難看出Int64的真實身份實為long型。
三元表達式
文法
表達式1?表達式2;表達式3
注意:
表達式2和表達式3的資料類型應該一緻;二者共同決定整個表達式的資料類型
舉例:
楔子:
<span style="font-family:KaiTi_GB2312;font-size:24px;">namespace 三元表達式之楔子
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("請輸入您的名字:");
string name = Console.ReadLine();
if (name == "joker")
{
Console.WriteLine("{0}是一位帥哥。", name);
}
else
{
Console.WriteLine("{0}是壞蛋", name);
}
Console.ReadKey();
}
}
}</span>
簡化:
<span style="font-family:KaiTi_GB2312;font-size:24px;">namespace 使用三元表達式簡化代碼
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("請輸入您的名字:");
string name =Console.ReadLine();
string result = name == "joker" ? "此人很純潔" : "此人很邪惡";
//上式中的result的類型取決于表達式2或者表達式3是什麼類型
Console.WriteLine(result );
Console.ReadKey();
}
}
}
</span>
從上面兩份代碼可以看出:三元表達式不僅可以簡化代碼,更能極大程度提升代碼的可維護性
随想:
這段時間由于補之前拉下的進度,最近更新的部落格均為占位所作,一如老師說過的“出來混總是要還的”。我會盡快補上之前占位所作的部落格,由此給大家帶來了不便,還望海涵。 分享給我在CSDN的APP看到的一句話: The most import thing is not that you have a dream,but that you have a dream and you have a strong plan to make your dream come true. Thanks for your precious time,enjoying~~