Consider this code:
class Program
{
static void Main(string[] args)
{
var instance = Activator.CreateInstance<Person>();//No parameterless constructor defined for this object.
}
}
public class Person
{
public Person(string name = "Shahrooz") { }
}
When use this code: Activator.CreateInstance<Person>();I get this error:
No parameterless constructor defined for this object.
Note that my constructor has default parameter:string name = "Shahrooz"
Why we can not create instance from a class that has constructor,despite the constructor has default value parameter?