Environment variable check with default value in csharp
Use ??. Null-coalescing operator.
Null check only
public static string GetEnvironmentVariable(string name, string defaultValue)
    =&gt; Environment.GetEnvironmentVariable(name) ?? defaultValue;

Null and empty string check
public static string GetEnvironmentVariable(string name, string defaultValue)
    =&gt; Environment.GetEnvironmentVariable(name) is string v &amp;&amp; v.Length &gt; 0 ? v : defaultValue;

Pattern matching.