類或方法名後加<>

聲明類型爲泛型。

說明傳遞的參數爲泛型,而不單單是一種類型。
public void aa<T>(T a)
{
Console.WriteLine(a);
}
調用時可寫:
this.aa<int>(5);
this.aa(string)("aaaa");

C#變量類型後面加?是什麼意思?

例如:
int? id = null;
string? name = null;
還有如:
ide

public int?[] InsertTest(int? parentId, string name, DateTime? publishTime, decimal? price, bool? isGood, out int? minId)
    {
        // 僅爲說明如何作錯誤處理
        if (String.IsNullOrEmpty(name))
            throw new ArgumentException("參數不能是空", "name");
 
        int? id = null;
        int? count = null;
        minId = null;
 
        Singleton<TestTableAdapter>.Instance.InsertTest(parentId, name, publishTime, price, isGood, ref id, ref count, ref minId);
        return new int?[] { id, count };
    }
更多 2
View Code

答:this

單問號---用於給變量設初值的時候,給變量(int類型)賦值爲null,而不是0!
雙問號---用於判斷並賦值,先判斷當前變量是否爲null,若是是就能夠賦一個新值,不然跳過!spa

相關文章
相關標籤/搜索