I am trying to check whether a file path is valid using the following code
foreach (int i in UniqueRandom(0, 4))
{
var wbImage = getCharBitmap(c, rndFolder, i);
}
The UniqueRandom
method generates non repeating random numbers between 0 to 4. Each number i
represents a file name, which may or may not exist. If the file exist, the getCharBitmap
method will return a WritableBitmap
object, otherwise, it will return null.
I want to integrate a lambda expression to check whether the method returns null or not, then, if it's not null, I want to remember the i
value and exit the foreach
loop right away.
How to do this efficiently with the least amount of code?