[英]List<string> checking null in C#
我在C#中有一個函數,代碼如下:
public IList<VW_CANDBASICSEARCH> GetAdvSearchCandidate(List<string> strSkill, List<string> strRole, string strOrganization, string strPosition, string strLocation)
{
//Code goes here
}
當我調用函數時,strSkill或strRole有時會變為null。但是如何檢查strRole / strSkill? 我已經嘗試過strSkill!= null,但是它給出了錯誤。
public IList<VW_CANDBASICSEARCH> GetAdvSearchCandidate(List<string> strSkill, List<string> strRole, string strOrganization, string strPosition, string strLocation)
{
if(strSkill == null)
{
throw new ArgumentNullException("strSkill");
}
// do all other checks
// your code
}
空檢查幾乎是標准過程。
旁注:您可能想讀一本有關C#編碼標准的好書。 除了null檢查外,它還解釋了變量和函數的命名。 您的代碼看起來像一個如何不做的例子。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.