I have an object and I have the name of a string property. How can I set the value to null?
I have tried the following but unforunatly c# converts null to the string "Null"
Data data = new Data();
PropertyInfo propertyInfo = data.GetType().GetProperty("StringProperty");
string valOrNull = null;
propertyInfo.SetValue(data, valOrNull, null);
//data.StringProperty is now "Null" instead of null
Aucun commentaire:
Enregistrer un commentaire