C# convert nullable to non-nullable (with reflection)

Date: 2019-10-24
object nullableObject = (int?)2; // nullable int, but we do not know
var type = Nullable.GetUnderlyingType(nullableObject.GetType()) ?? nullableObject.GetType(); // get the underlying type (int)
var nonNullableObject = Convert.ChangeType(nullableObject, type); // convert int? to int
27130cookie-checkC# convert nullable to non-nullable (with reflection)