If I use a .Any() to check if a list/collection contains values, is it possible to somehow use those values to avoid calling a separate .Where()?
for example:
if(thisList.Any(i => i.fieldCheck == thingToCheck)
{
//use i here instead of thisList.Where(i => i.fieldCheck == thingToCheck)
}
Edit for clarity: I am using the .Any essentially as a null check so that I can safely use any results of Where without having to do other checks. Rather than writing the code for assigning something to .Where I wanted to use any values that matched in the .Any instead
Where()
Any()
does return only a boolean, and does not enumerate all the values so you should consider other functions likeWhere(condition)
.