Check if value tuple is default

  • A+
Category:Languages

How to check if a System.ValueTuple is default? Rough example:

(string foo, string bar) MyMethod() => default;  // Later var result = MyMethod(); if (result is default){ } // doesnt work 

I can return a default value in MyMethod using default syntax of C# 7.2. I cannot check for default case back? These are what I tried:

result is default result == default result is default(string, string) result == default(string, string) 


If you really want to keep it returning default, you could use

result.Equals(default) 

the built-in Equals method of a ValueTuple should work.

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: