How does GetValueOrDefault work?

thing isn’t null. Since structs can’t be null, so Nullable<int> can’t be null.

The thing is… it is just compiler magic. You think it is null. In fact, the HasValue is just set to false.

If you call GetValueOrDefault it checks if HasValue is true or false:

public T GetValueOrDefault(T defaultValue)
{
    return HasValue ? value : defaultValue;
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)