Was funktioniert schneller? Null Coalesce, Ternary oder If Statement [closed]
Wir gebrauchen?? Operator um Ausdrücke gegen Nullwerte auszuwerten, zum Beispiel:
string foo = null;
string bar = "woooo";
string foobar= foo ?? bar ;
// Evaluates foobar as woooo
Wir haben auch eineif
Anweisung, die genauso funktioniert, wenn sie mit dem obigen Ausdruck verwendet wird
string foo = null;
string bar = "woooo";
if(foo==null)
string foobar= "woooo" ;
// Evaluates foobar as woooo same as above
Und auch?: Ternärer Operator...
string foo = null;
string bar = "woooo";
string foobar= foo==null ? "woooo" : null ;
// Evaluates foobar as woooo same as above
Ich weiß, dass Null-Koaleszenz in der Syntax präzise ist, aber welche wird unter beiden schneller kompiliert und ist schneller und warum?