title: C# dynamic logic gate
body: <p>I am working on a program that would allow the user to build digital circuits from virtual logic gates. Every gate would be an instance of a class that represents particular gate type, for example here's how AND class looks:</p>
  
  <pre><code>public class andgate
  {
      public andgate()
      {
          inputs = new bool[7];
          for (int i = 0; i &lt; 7; i++) inputs[i] = true;
          output = (inputs[0] &amp;&amp; inputs[1] &amp;&amp; inputs[2] &amp;&amp; inputs[3] &amp;&amp; inputs[4] &amp;&amp; inputs[5] &amp;&amp; inputs[6]);
      }
      public bool[] inputs;
      public bool output;
  }
  </code></pre>
  
  <p>Every gate has seven inputs but not all of them have to be used (i.e. for a gate with three imputs the remaining four will just be "1" which is AND's neutral element anyway). Each input is a reference to an output of another gate or to an element of bool array (which stores the input vector) so that signal generated by one gate automatically is sent to the following gate. The problem is I also need the signal to be transmitted dynamically within the gate, i.e. if one of the input signals in AND gate is set to 0 then the output automatically has a 0 value. Therefore when you feed a binary vector to the inputs of the cirtuit, it changes the values of the circuit's outputs. Or maybe there's an easier way to simulate a circuit than building it from individual gates? I need it for test pattern generating.</p>