Mark Tabor

Mark Tabor

  • 587
  • 2k
  • 460.6k

IF and else condition in c#

May 28 2022 6:13 AM

Dear all I have a code 

if (findCNIC != null)
{
    if (findCNIC.DISTRICT.ToUpper() == "ABC")
    {
        district = "NEW";
    }
    else if (findCNIC.TEHSIL.ToUpper() == "ZHS" || findCNIC.TEHSIL.ToUpper() == "BHHH")
    {
        district = "old";
    }
    else if (findCNIC.TEHSIL.ToUpper() == "NO" || findCNIC.TEHSIL.ToUpper() == "NO")
    {
        district = "mid";
    }
    else { district = findCNIC.DISTRICT.ToUpper(); }
}

Now I wanted to check findCNIC.TEHSIL is not null above to this else if 

  else if (findCNIC.TEHSIL.ToUpper() == "ZHS" || findCNIC.TEHSIL.ToUpper() == "BHHH")

how to do that because I am getting exception when tehsil is coming null , remember I  want to check this condition with else if not with main if.


Answers (1)