Trial #11: Does C# have something like php’s isset()?
Problem:
I’ve been making a dogs ear of an if statement in PowerShell but what I need is an isset like method.
if($var1 -eq $null -or $var1 -eq ""){ "There must be a much better way" }
elseif($var2 -ne $null -and $var2 -ne ""){"This is even worse"}
Solution:
Enter .Net static method [string]::IsNullOrEmpty()
if( [string]::IsNullOrEmpty($var1) ){ "Phew" }
elseif( !([string]::IsNullOrEmpty($var2)) ){"That's a relief"}
Pitfalls
- This is just a rare good thing
Leave a comment