mardi 21 juin 2016

How can I set the value of a variable?

I have found this example to set the value of a Class property:

Ship ship = new Ship();
string value = "5.5";
var property = ship.GetType().GetProperty("Latitude");
var convertedValue = property.Converter.ConvertFrom(value);
property.SetValue(self, convertedValue);

But I want to set value of a variable in my "this".

i.e. in my main form I have a private double "Momentum"

string value = "5.5";
var property = this.GetType().GetProperty("Momentum");
var convertedValue = property.Converter.ConvertFrom(value);
property.SetValue(self, convertedValue);

This does NOT work - "property" is null.

How do I alter the above code to achieve this?





Aucun commentaire:

Enregistrer un commentaire