title: Property name as variable
body: <p>I need to find the biggest size of each string column in a database as one of the informations to design another database. The only access I have to the source database is by a web service. I can just do it for each of the many columns to find the biggest size but I want it generic so I can use it later.</p>
  
  <p>I wrote this very simplified version to make it simple to understand. Two of the last lines have invented syntax and it is where I need help.</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  
  namespace ConsoleApplication1
  {
      public class myClass
      {
          private string s;
          public string S
          {
              get { return s; }
              set { s = value; }
          }
          private int i;
          public int I
          {
              get { return i; }
              set { i = value; }
          }
      }
  
      class Program
      {
          static void Main(string[] args)
          {
              Type myClassType = typeof(myClass);
              System.Reflection.PropertyInfo[] propertyInfo = myClassType.GetProperties();
              Dictionary&lt;string, int&gt; property = new Dictionary&lt;string, int&gt;();
  
              foreach (System.Reflection.PropertyInfo info in propertyInfo)
                 if (info.PropertyType == typeof(System.String))
                      property.Add(info.Name, -1);
  
              myClass[] myPa = new myClass[2];
              myPa[0] = new myClass();
              myPa[0].S = "1";
              myPa[0].I = 0;
              myPa[1] = new myClass();
              myPa[1].S = "12";
              myPa[1].I = 1;
  </code></pre>
  
  <p>This is where I need help. I invented the <code>c[pair.key]</code>. How to have a reference to a property that I know the name of?</p>
  
  <pre><code>            foreach (myClass c in myPa)
                  foreach (KeyValuePair&lt;string, int&gt; pair in property)
                      if (c[pair.Key].Length &gt; pair.Value)
                          property[pair.Key] = c[pair.Key].Length;
  
              foreach (KeyValuePair&lt;string, int&gt; pair in property)
                  Console.WriteLine("Property: {0}, Biggest Size: {1}", pair.Key, pair.Value);
          }
      }
  }
  </code></pre>
  
  <p>Output shoud be:</p>
  
  <pre><code>Property: S Biggest Size: 2
  </code></pre>