HasValueAndEquals

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))...

Description

Substitutes this: int? index = GetIndex(); if (index.HasValue && index.Value == 10) ...

Details

Double click on the code to select all.

 

;