Grasshopper

algorithmic modeling for Rhino

Hi, all!!

 

How can I check with a list of booleans in C#?

 

For example, if I have a list of booleans,

(true, true, true, false)

 

then, is there a way to check it with all and pass 'false'?

 

I guess I can use '&&' conditions...but thiese number of booleans will be varying.

Views: 765

Replies to This Discussion

Hi YJ,

 

public bool AllBooleansTrue(List<bool> blist)

{

  for (int i = 0; i < blist.Count; i++)

  {

    if (!blist[i]) { return false; }

  }

  return true;

}

 

You could also use a Predicate and the TrueForAll() method on List<> to check this.

 

Finally, to accomplish this without scripting, use the MassAddition component to sum all Booleans together, and if the final result equals the number of items, all of them were True.

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Thanks all times, David!!

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service