How do I check if a Guid value is inside a LIST of Structures?

How do I check if a Guid value is inside a LIST of Structures?

public struct Info
{
   public Guid EntityTypeID;
   public String Name;
}


List<Info> InfoList = <function which populates the list of Struct>
...

var values = ctx.EntityValues.Where(v => v.EntityID == e.ID
                               && InfoList.Contains(v.EntityTypeItemID)).ToList(); <=== problem here!
                //or something like: InfoList[i].EntityTypeID.Contains(v.EntityTypeItemID)).ToList();

Thank you

Jon Skeet
people
quotationmark

I suspect you're looking for Any:

... InfoList.Any(x => x.EntityTypeID == v.EntityTypeItemID)

You can't use Contains, because you're looking for something which matches part of the item.

(I'd also strongly discourage using public fields and indeed having mutable structures at all, but that's a different matter.)

Another option would be to create a list of the GUIDs you're interested in:

var guids = InfoList.Select(x => x.EntityTypeID).ToList();

Then you can use:

... guids.Contains(v.EntityTypeItemID)

That may work where the previous code didn't, as it moves the extraction of the type ID out of the main query.

people

See more on this question at Stackoverflow