I have generic class Name car, Car accepted datatype "Class Type". I get from a database the name of class as string, so I convert string to class type than I pass that class to generic type class, but I always I get error " Error "'o' is a variable but is used like a type". How I can pass Door class to Car generic class.
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
string nameOfClass = "ConsoleApplication2.Door";
Door o = (Door)System.Activator.CreateInstance(Type.GetType(nameOfClass));
Console.WriteLine("Type: {0}\nValue: {1}\nHashCode: {2}\n",
o.GetType().FullName, o.ToString(), o.GetHashCode());
Console.ReadLine();
//error in O
Car<o> l = new Car<o>();
}
}
class Car<T> where T : class
{
public void carName(T name)
{}
}
class Door
{}
}