简体   繁体   中英

List<string> checking null in C#

I have a function in C#.The code is given below:

public IList<VW_CANDBASICSEARCH> GetAdvSearchCandidate(List<string> strSkill, List<string> strRole, string strOrganization, string strPosition, string strLocation)
{

    //Code goes here
}

when I am calling the function sometimes strSkill or strRole become null.But how to check strRole/strSkill? I have tried strSkill!=null but it gives error.

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
}

Null-checks are pretty much standard procedure.

SideNote: you may want to read a good book on C# coding standards. Apart from null checks it also explains variable and function naming. You code looks like an example of how to not do it.

Either as a book: Framework Design Guidelines or as a MSDN page here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM