1

I've got an array var cells = new Cell[w, h], can I loop through all cells without a nested for-loop (I want to check if at least one is null)? Ideally I'd want to write something like Debug.Assert(!cells.Contains(null)).

1 Answer 1

2

foreach loop ?

foreach (var item in cells)
{
    //code
}
Sign up to request clarification or add additional context in comments.

2 Comments

+1 I think this is the easiest way of doing it out of the box.
Thanks. Also I just found another way: Debug.Assert(!cells.Cast<Cell>().Contains(null)). I wonder why the "Cast" is needed. An "AsEnumerable" or "Flattened" function would have been more intuitive.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.