int?

double?

表示除了原有的型別資料外,也能儲存NULL.

在C#中有分value type和reference type,而value type預設是不能有null

而你在變數型態後加上問號,就讓這個變數可以儲存null

但之後取值時要用轉型或加上 .value,像下要的例子

int? abc =123;

int def = abc; //不能直接這樣給

int def = (int)abc; //做法一

int def = abc.value; //做法二

 

arrow
arrow
    文章標籤
    C# int? double? question mark
    全站熱搜

    痞客興 發表在 痞客邦 留言(0) 人氣()