0

I am getting Object Null Reference error. I tried checking for null as done below but I am still getting the error.

List<Data> gvdta = (List<Data>)Session["Items"];
switch (this.dd_search.SelectedValue)
{
    case "emp":                
    var tb = (from ad in gvdta
              where ad!=null & ad.emp.ToLower().Contains(this.txt_Search.Text.ToLower())
              select ad);
       gvdta = tb.ToList();            
    break;
}

Is there any other way? Please help.Thank you.

Sumedha Vangury
  • 623
  • 1
  • 12
  • 40

1 Answers1

2

Use && operator in

where ad!=null && ad.emp.ToLower().Contains(this.txt_Search.Text.ToLower()). 

& is bitwise operator where both sides will be always evaluated. From & Operator (C# Reference)

The & operator evaluates both operators regardless of the first one's value.

From && Operator (C# Reference)

The conditional-AND operator (&&) performs a logical-AND of its bool operands, but only evaluates its second operand if necessary.

Fabio
  • 28,602
  • 3
  • 26
  • 58