HasValueAndEquals
Substitutes this: int? index = GetIndex(); if (index.HasValue && index.Value == 10) ...
Source
public static bool HasValueAndEquals<T>(this Nullable<T> source, T target)
where T : struct
{
return source.HasValue && source.Value.Equals(target);
}
public static bool HasValueAndEquals<T>(this Nullable<T> source, Nullable<T> target)
where T : struct
{
return source.HasValue && source.Value.Equals(target);
}
Example
int? index = GetIndex();
if (index.HasValueAndEquals(10))...