Hi, buddies. I have a trouble with searching objects with lambda-expressions (using method “Exists” defined in System.Linq) in IList objects. The point is that I have a read-only copy of the list made by AsReadOnly method, that creates an IList Object. But the method “Exists” is not defined for this interface. I can convert it with ToList() operation to implement Exists to the resulting object, but I’m not sure that it’s an effective to call every FixedUpdate iteration. Is there more optimal way to do it?
Use the Any
method.
if(tt.Applicants.Any (x => /*condition*/)){
// Do something
}
Any
is defined in Linq and works for any IEnumerable
.
Also:
The Exists
method actually is not in Linq
. It is defined only on List
. If you already have a list use Exists
since it is faster than Any
.