title: Validate bool methods (constraints) in list
body: <p>I'm wondering if this is possible:</p>
  
  <p>I would like to have a list where I can add bool methods to and validate those methods and when they are all true, return true. When at least one is false, return false.</p>
  
  <p>Problem is, when I do something like:</p>
  
  <pre><code>private int _value1, _value2, _value3, _value4;
  
  private bool check2()
  {
      return _value2 + _value3 &gt; _value4;
  }
  
  private bool check2()
  {
     return _value2 + _value3 &gt; _value4;
  }
  
  List&lt;bool&gt; constraints = new List&lt;bool&gt;();
  constrains.Add(check1());
  constrains.Add(check2());
  </code></pre>
  
  <p>the bools added are of course the result of the validation when added to the list. I get that ;-)</p>
  
  <p>How can I make a list with methods, that are actually re-validated?
  Kind regards,</p>
  
  <p>Matthijs</p>
  
  <p><strong>This is what I wanted.</strong></p>
  
  <p>With the help of the answers below. I made this. Might be useful for others looking for the same thing.</p>
  
  <pre><code>public class TestClass
  {
      private int _value1, _value2, _value3, _value4;
  
      private void button1_Click(object sender, EventArgs e)
      {
          ConstraintsList cl = new ConstraintsList();
          cl.Add(check1);
          cl.Add(check2);
  
          bool test1 = cl.AllTrue;
          bool test2 = cl.AnyTrue;
  
          _value4 = -5;
  
          bool test3 = cl.AllTrue;
          bool test4 = cl.AnyTrue;
  
          _value4 = 5;
  
          cl.Remove(check2);
  
          bool test5 = cl.AllTrue;
          bool test6 = cl.AnyTrue;
      }
  
      private bool check1()
      {
          return _value1 + _value2 == _value3;
      }
  
      private bool check2()
      {
          return _value2 + _value3 &gt; _value4;
      }
  
  }
  </code></pre>
  
  <p>using:</p>
  
  <pre><code>public class ConstraintsList
  {
      private HashSet&lt;Func&lt;bool&gt;&gt; constraints = new HashSet&lt;Func&lt;bool&gt;&gt;();
  
      public void Add(Func&lt;bool&gt; item)
      {
          try
          {
              constraints.Add(item);
          }
          catch(Exception)
          {
  
              throw;
          }
      }
  
      public bool AllTrue { get { return constraints.All(c =&gt; c()); } }
      public bool AnyTrue { get { return constraints.Any(c =&gt; c()); } }
  
      public void Remove(Func&lt;bool&gt; item)
      {
          try
          {
              constraints.Remove(item);
          }
          catch(Exception)
          {
              throw;
          }
  
      }
  }
  </code></pre>