0

I have a list as follows:

public class Emp
{
  public string? Name {get;set;}
  public int? Id {get;set;}
}

I have a list as:

List<Emp> empList = new List<Emp>();

The input for the list is:

{"A",null}
{null,null}

I want to check if Name in the list has value for atleast for one object. In this case , since "A" is present I should get true. Similarly If I ask for ID , I should get false because both are null.

I tried this: Edit:

if(empList.Any(x=> x.Name != null))

I get an error:

"Expression cannot contain lambda expressions"

How do I check it?

Edit: Making the property as nullable

Mong Zhu
  • 23,309
  • 10
  • 44
  • 76
user2630764
  • 624
  • 1
  • 8
  • 19
  • This code does not give that compiler error. Are you running the `Any()` in a Watch or Immediate Window? – CodeCaster Dec 02 '16 at 11:41
  • @CodeCaster : Yes I am using using in Watch – user2630764 Dec 02 '16 at 11:42
  • You can't. See [duplicate](http://stackoverflow.com/questions/725499/vs-debugging-quick-watch-tool-and-lambda-expressions) and [Expression cannot contain lambda expressions](http://stackoverflow.com/questions/23470607/expression-cannot-contain-lambda-expressions). – CodeCaster Dec 02 '16 at 11:43

0 Answers0