Users Pricing

forum

Home Forums Find in List<t> and return boolean if found – MindStick

Find in List<t> and return boolean if found

Anonymous User 2562 29 Jan 2014

public class MyType

{

    public string MyName;

    public string MyTown;

    public string MyJob;

}

I have a List of this type:

List<MyType> myVar = new List<MyType>()

Now I want to return a boolean based on this. So for example: Does myVar contain MyName = "Bob" and MyJob = "Taxi Driver"

I have managed to return all with a name of "Bob"

var e = myVar.Where(x => x.MyName== "Bob").ToList();

But I want to do something like:

bool mExists = (myVar.Where(x => x.MyName== "Bob" && MyJob="Taxi Driver").Count > 0) ? true : false;

Is this possible?


1 Answers

Markdown for AI

A clean, structured version of this page for AI assistants and LLMs.

Open .md