You can use the null-coalescing operator :
bool isAdvancedMode = (Request.QueryString["mode"] ?? String.Empty).Equals("advanced");
Edit: If you want to reuse this logic, try this extension method:
public static bool EqualIfExists(this string source, string comparison) { return source != null && source.Equals(comparison); } Request.QueryString["mode"].EqualIfExists("advanced")
Add more overrides to match the Equals signature. I am not sure if this is a good name (I think it is not).
source share