vendredi 24 juillet 2015

How do I declare and invoke a C# object when given the object name as a string?

I have a lot of classes written and I receive a String. I want directly to declare and initiate the class that the value of the String is. I don't want to browse every single class written to see which is. Here is an example:

class Car
{
      public void startCar()
      {
            Console.WriteLine("Car started");
      }
}

class Main
{
      private void treeView1_Click(object sender, EventArgs e)
      {
         String s="Car"
        // I said Car obj because that's the value of the string
         Car obj = new Car();

         // or like this
         value.string obj = new value.string();
         obj.startCar();


      }



}





Aucun commentaire:

Enregistrer un commentaire