title: Assign property address to another property (reference). Change property when another property is changed. c#
body: <p>I would like to assing one property to another in different class. Change this property automatically when passed property is changed. Something like reference the same address in c++. Is it possible in C#?</p>
  <p>I want to achieve effect that when base property &quot;IsOpen&quot; in PressureValve class is changed, in the same time automatically propert &quot;IsEnabled&quot; in Component class is changed.</p>
  <p>Thank you in advance for any help.</p>
  <p>Classes:</p>
  <pre class="lang-c prettyprint-override"><code>    class Component
      {
          public Component(int id, string description, ref anotherPropertyFromDifferentClass)
          {
              Id = id;
              Description = description;
              //Assign IsEnabled to another property, change it always when anotherPropertyFromDifferentClass is changed.
              IsEnabled = ref anotherPropertyFromDifferentClass;
          }
          public int Id { get; set; }
          public string Description { get; set; }
          public bool IsEnabled { get; set; }
      }
      class PressureValve
      {
          public bool IsOpen { get; set; }
      }
  </code></pre>
  <p>Program:</p>
  <pre class="lang-c prettyprint-override"><code>            PressureValve pressureValve = new PressureValve();
             
              //status read from external device, changing during programm running
              pressureValve.IsOpen = externalInfo;
              //create component, change component IsEnabled property automatically when pressureValve.IsOpen is changed
              Component component = new Component(1,&quot;Valve status&quot;, ref pressureValve.IsOpen)
  
  
  
   
  </code></pre>
  <p>Edit:
  I would like to extend functionality suggested in accepted answer.
  How to assign property from CommonProperty dynamically?</p>
  <p>Example, more than one property in CommonPropertyclass:</p>
  <pre><code>    class CommonProperty //Change this class name to Your desired one.
  {
      public bool IsOpen { get; set; }
  public bool IsPoweredUp{ get; set; }
  public bool IsRunning{ get; set; }
  
  }
  </code></pre>
  <p>Then I would like to have multiple objects of Component class</p>
  <pre><code>class Component
  {
      public int Id { get; set; }
      public string Description { get; set; }
      public bool IsEnabled =&gt;  //Here to assign property dynamically while creating object.
      public CommonProperty ValveStatus { get; } //Set this only on Constructor since we want to update it automatically through the object reference
  
      public Component(int id, string description, CommonProperty valveStatus)
      {
          Id = id;
          Description = description;
          ValveStatus = valveStatus;
          //Assign IsEnabled to another property, change it always when anotherPropertyFromDifferentClass is changed.
      }
  }
  </code></pre>
  <p>And creation of object:</p>
  <pre><code>//create component, change component IsEnabled property automatically when assigned property from pressureValve is changed
  Component component = new Component(1, &quot;Valve status&quot;, commonProp, propertyName or type?);
  </code></pre>