Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

2D boolean array, check if array contains a false

Tags:

arrays

c#

I'm using a 2D array of booleans in C#. I've looked up the Array.Exists function at dot net pearls but I can't get it to work, either because I'm using booleans or because it's a 2D array.

bool[,] array = new bool[4, 4];

if (array.Contains(false)) {}; // This line is pseudo coded to show what I'm looking for
like image 217
Juicy Avatar asked Dec 03 '22 20:12

Juicy


1 Answers

Don't know if this is the proper way or not but casting each element seems to work:

bool[,] a = new bool[4,4]
    {
        {true, true, true, true},
        {true, true, false, true},
        {true, true, true, true},
        {true, true, true, true},
    };

    if(a.Cast<bool>().Contains(false))
    {
        Console.Write("Contains false");
    }
like image 106
pcnThird Avatar answered Dec 18 '22 10:12

pcnThird