dimanche 25 novembre 2018

c# short record "if" without "else"

I have the following statement:

if (!text.Equals("PRO_QUIP ID", StringComparison.CurrentCultureIgnoreCase))
     throw new Exception();

any way to write it shorter? I try to do it:

(text.Equals("PRO_QUIP ID", StringComparison.CurrentCultureIgnoreCase) == true) ?? throw new Exception();

but I get:

Operator '??' cannot be applied to operands of type 'bool' and 'throw expression'

Aucun commentaire:

Enregistrer un commentaire