-3

I've come apon this syntax a few times in programming books and other open source programs I've been looking at.

return am == null ? "": (String) am.get();

or

return Level != 0 ? String.format("({0})", Level) : "";

What is this pattern called? I've tried searching for the value ? value : value; type pattern hoping it would come up both here and on google, but so far no luck. I think I know what it's doing but I would love to know what to call it to learn more.

ryuzoku
  • 1
  • 3
  • Thanks, i've only seen it in return statements so far, never thought of it as used outside of that. I find it strange someone would ask for it as a `? :`. the values seem integral to figuring it out. There should be a way to make it easier to find these multiples. – ryuzoku May 31 '15 at 00:41

1 Answers1

0

That's a "ternary operator," also known as a "conditional operator": condition ? valueIfTrue : valueIfFalse.

To my knowledge there's no special name for it when it's used in a return statement.

elixenide
  • 44,308
  • 16
  • 74
  • 100