title: Object properties updating between instances C#
body: <p>I have got 4 instances of a service class within a WPF application that is updating all 4 instances when one of the complex properties change, the same changes are applied to all the instances.
  The class looks like this:</p>
  
  <pre><code>public class ExampleClass
  {
      private IEnumerable&lt;SomeComplexType&gt; _status;
      public int InstanceNumber { get; set; }
  
      public IEnumerable&lt;SomeComplexType&gt; Status
      {
          get { return _status; }
          set { _status = value; }
      }
  
      public Task DoSomeWork()
      {
          var t = Task.Run(() =&gt;
          {
              var random = new Random();
              int i = 1;
              foreach (var item in Status)
              {
                  item.SomeValue = random.NextDouble();
                  item.ItemNumber = (InstanceNumber*i);
                  i++;
              }
              UpdateInterface();
          });
          return t;
      }
  
      public void UpdateInterface()
      {
          var message = new UpdateMessage {InstanceNumber = InstanceNumber, Status = Status};
          Messenger.Default.Send(message);
      }
  }
  </code></pre>
  
  <p>With the supporting types being similar to the following:</p>
  
  <pre><code>    class SomeComplexType
  {
      public double SomeValue { get; set; }
      public int ItemNumber { get; set; }
  }
  
  class  UpdateMessage
  {
      public int InstanceNumber { get; set; }
      public IEnumerable&lt;SomeComplexType&gt; Status { get; set; }
  }
  </code></pre>
  
  <p>Now when the <em>DoSomeWork()</em> method is called on instance 1, it works as expected. 
  Same when the <em>DoSomeWork()</em> method is then called on instance 2, but after instance 2 has updated, the <em>UpdateInterface()</em> function on instance 1 returns the status value of instance 2, even though the correct instance number is returned.</p>
  
  <p>Can anyone explain this behavior?</p>
  
  <p>The calling code is a simple function triggered by a button press:</p>
  
  <pre><code>public ICommand OnTestClickCommand
  {
      get { return _onTestClickCommand ?? (_onTestClickCommand = new RelayCommand(ButtonTestClick); }
  }
  
  private async void ButtonTestClick()
  {
      await ExampleClass.DoSomeWork;
  }
  </code></pre>
  
  <p>EDIT:
  The problem was in the ctor of each class, which looked like this:</p>
  
  <pre><code>    public ExampleClass(SomeDefaultClass default)
      {
          Status = default.Status;
      }
  </code></pre>
  
  <p>The same default variable was passed in when creating each instance. Should have included that in the original ask. This only passes the reference as stated in the comments. </p>