I have a List of Activity. In the Activity class is an ID property (a Guid for arguments sake). I want to check if this list has an Activity in it with a Guid I have. Rather
Sure.
foreach(Activity activity in ActivityList.Where(a => a.Id == GuidToCompare) )
{
//Code here
}
But since Id
implies there will be at most 1 activity:
//var act = ActivityList.Where(a => a.Id == GuidToCompare).SingleOrDefault(); // clearer
var act = ActivityList.SingleOrDefault(a => a.Id == GuidToCompare); // shorter
if (act != null)
{
//Code here
}