title: How can I use an array in a ViewModel?
body: <p>My code looks like this right now with two lines of code for each message. The code works but if I have for example 30 messages that I can each give values to then I will need to have 60 lines of code just to declare everything:</p>
  
  <pre><code>string _msg1;
  string _msg2;
  public string Msg1 { get =&gt; _msg1; set =&gt; SetProperty(ref _msg1, value); }
  public string Msg2 { get =&gt; _msg2; set =&gt; SetProperty(ref _msg2, value); }
  </code></pre>
  
  <p>and in C# I assign to these:</p>
  
  <pre><code>vm.Msg1 = "A";
  vm.Msg2 = "B"; 
  </code></pre>
  
  <p>and in the XAML I bind my Text to Msg1 and another Text to Msg2</p>
  
  <p>Can someone tell me how / if I can do this with array so that I would assign like this and hopefully so the assignment of the array can just be done in two lines instead of 2 lines for every single message:</p>
  
  <pre><code>vm.Msg[0] = "A";
  vm.Msg[1] = "B";
  </code></pre>
  
  <p>For reference:</p>
  
  <pre><code>public class ObservableObject : INotifyPropertyChanged
  {
  
      protected virtual bool SetProperty&lt;T&gt;(
          ref T backingStore, T value,
          [CallerMemberName]string propertyName = "",
          Action onChanged = null)
      {
          if (EqualityComparer&lt;T&gt;.Default.Equals(backingStore, value))
              return false;
  
          backingStore = value;
          onChanged?.Invoke();
          OnPropertyChanged(propertyName);
          return true;
      }
  
      public event PropertyChangedEventHandler PropertyChanged;
      protected virtual void OnPropertyChanged([CallerMemberName]string propertyName = "") =&gt;
          PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  
  }
  </code></pre>