title: C# List<T> / List<class> get values
body: <p>I write to my class different values and I would like to get the values of my class. The Debug outputs shows me:</p>
  
  <p>Value: List.data Index 0
  Value: List.data Index 1</p>
  
  <p>How I get the real value of my class properties?</p>
  
  <p>My code example:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using System.Drawing;
  using System.Diagnostics;
  
  namespace List
  {
      class data
      {
          public string name { get; set; }
          public Rectangle rect { get; set; }
      }
  
      class Program
      {
          static void Main(string[] args)
          {
  
              data dat1 = new data();
              List&lt;data&gt; listdat = new List&lt;data&gt;();
              dat1.name = "test1";
              dat1.rect = new Rectangle(10, 10, 10, 10);
              listdat.Add(dat1);
  
              data dat2 = new data();
              dat2.name = "test2";
              dat2.rect = new Rectangle(20, 20, 20, 20);
              listdat.Add(dat2);
  
              data dat3 = new data();
              dat3.name = "test3";
              dat3.rect = new Rectangle(30, 30, 30, 30);
              listdat.Add(dat3);
  
              listdat.RemoveAt(1);
              foreach (var item in listdat)
              {
                  //This will yield the proper index that you are currently on
                  int index = listdat.IndexOf(item);
              }
  
              foreach (var item in listdat.Select((value, index) =&gt; new { Value = value, Index = index }))
              {
                  //Get the value through item.Value;
                  var currentValue = item.Value;
                  //Get the index through item.Index;
                  int currentIndex = item.Index;
                  Debug.WriteLine("Value: {0} Index {1}", currentValue, currentIndex);
              }
              int i = 0;
          }
      }
  }
  </code></pre>