amitabha
amitabha

Reputation: 646

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.

Upvotes: 0

Views: 119

Answers (1)

nvoigt
nvoigt

Reputation: 77294

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.

Upvotes: 1

Related Questions