[英]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.