DEV Community

wk
wk

Posted on

2 1

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?

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay