DEV Community

wk
wk

Posted on

Ternary operator in C# 8

class Point {
  public int X { set; get; }
  public int Y { set; get; }
}


string IsOrigin(Point point) =>
  point is { X: 0, Y: 0 } ? "T" : "F";


var point = new Point { X = 0, Y = 0 };
var result = IsOrigin(point);

Top comments (2)

Collapse
 
jrpacheco profile image
Júnior Pacheco

Cool

Collapse
 
saint4eva profile image
saint4eva

Nice one. I believe you utilized positional pattern matching?