title: Dynamic object reference C#
body: <p>I created a method Mydata to assign the new data form the list (listData). But the way I am doing this is not dynamically and I am using an if else statement to determine how many data to add and in which property it belongs. Is there a way to simplify this or make it dynamically, without using if else statement. </p>
  
  <pre><code>public List&lt;Data&gt; _newData = new List&lt;Data&gt;();
  
  public void Mydata(int number, List&lt;string&gt; listData) {
               if (number == 1) {
                _newData.Add(new Data() {
                         variable0 = listData[0].ToString(),
                   });
               } 
               else if (number == 2) {
               _newData.Add(new Data() {
                         variable0 = listData[0].ToString(),
                         variable1 = listData[1].ToString(),
                   });    
                 }
               else if (number == 3) {
               _newData.Add(new Data() {
                         variable0 = listData[0].ToString(),
                         variable1 = listData[1].ToString(),
                         variable2 = listData[2].ToString(),
                   });    
                 } 
  
  
  class Data
  {
    public string variable1 { get; set; }
    public string variable2 { get; set; }
    public string variable3 { get; set; }
    public string variable4 { get; set; }
    ..
    public string variable10 { get; set; }
  }
  </code></pre>