I have a bool array
a[1] = true
a[2] = false
a[3] = true
a[4] = true
how do i select only true values to a new array?
Thanks!
I don't really know why you would want to do this but...
bool[] a = {true, false, true, true};
bool[] b = a.Where(x => x).ToArray();
If you just want to count how many "true"s there are:
int c = a.Count(x => x);
boolVar == true check. It's not very good code.== true part is not necessary. Sometimes, people just copy and paste code they get in answers here into their IDE.boolVar == true check," other than to save a few keystrokes. If you think that's bad code, perhaps you should indicate why.
true?bool[] arrayName;How do I know? Because that's how you declare arrays in C#. I don't see how this is possibly relevant.[]operator and type conversion tobool".