This question already has an answer here:
Let's say I have such struct:
public struct Dog
{
public Dog(string name)
{
Name = name;
}
public string Name { get; set; }
}
Why does the following code not crash ?
var dog = Activator.CreateInstance<Dog>();
If Dog was a class there would be a runtime error. But with a struct the instance is created with a null Name.
Aucun commentaire:
Enregistrer un commentaire