Last post Jul 08, 2014 06:11 AM by AidyF
Jul 08, 2014 05:56 AM|GStar99|LINK
I have a string variable that represents the name of a child class. Example:
string s = "CustomerA"
I will need to create a customer using the base class. So, the syntax needed is:
Customer cust = new ..
what is the sytax?
I've had a look at the activator.create instance method but I cant really figure out the syntax
Customer cust = (Customer)Activator.CreateInstance(Type.GetType("CustomerA"));
Using the above gives me the following error
Value cannot be null. Parameter name: type
Jul 08, 2014 06:11 AM|AidyF|LINK
Your code is fine, however you need to provide the full type name, not just the class name.
string s = "YourNamespace.CustomerA";