U
U
Uncle Bogdan2021-07-07 20:49:15
C++ / C#
Uncle Bogdan, 2021-07-07 20:49:15

How to make random element in .Find/.FirstOrDefault?

He chooses the first one by condition, but how can you choose random with such conditions?
It is possible, of course, through a loop, but is it possible somehow in one line?

Brawler RandomBrawler = null;

RandomBrawler = player.PlayerBrawlers.FirstOrDefault(item => item.Level >= 7 && item.Starpowers.Any(x => x.Have == false));

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vasily Bannikov, 2021-07-07
@motkot

ToArray()
and choose random by index

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question