Q:

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?

A:

Seriously, why are you using reflection if you need to set the field value from a variable you own?
Okay, let's forget that... If you have a field and not a property, you need to use GetField:
var value = "5.5";
var field = this.GetType().GetField(nameof(Momentum), BindingFlags.NonPublic);
field.SetValue(self /* or this */, value);

Also, this might be a good place to use nameof, but that is just a suggestion.

