So I have a list of instances of classes like
Imagine you have Slime.cs and you have multiple slimes in a list: List slime = new List();
And each slime class has a bool hasHit; and you wanna check if every slime in the List has hasHit to be true. How would you do that? I understand there’s enumerable All but wouldn’t that only work for a list/array of bools? I don’t know how to do that for a List of instances of a class
I tried to use Enumerable All, I tried using foreach and for loops too
>Solution :
Try this:
List<Slime> slimes = new List<Slime>();
bool allShasHit = slimes.All(slime => slime.hasHit);
See Microsoft All Documentation