title: Сasting a variable to a type without switch case
body: <p>I have a list of objects <code>ListOfObjects</code> that are all of the same type, but the specific type is not known (however, I do know all the possible types). There are 
   many possible types. Each object has the property <code>Name</code>, which is a string of its type. I want do something like the following:</p>
  
  <pre><code>foreach (object elements in ListOfObjects)
  {
      // Some code here that casts elements into the specific type and pass it into another function
  }
  </code></pre>
  
  <p>I know one way to do this is to use a switch case statement</p>
  
  <pre><code>  switch (ListOfObjects[0].Name)
    {
        case "Type1":
            //cast into Type1 and pass into function
        case "Type2":
            //cast into Type2 and pass into function
        default:
            //something
            break;
    }
  </code></pre>
  
  <p>Is there a cleaner way to do this? Is is possible to store the possible Types in a dictionary and cast from that dictionary?</p>