0

In C++ the ternary operator below will return 1.

true ? 0 : 1

In C# it will return 0.

If the following is written in C++

int x = ((a < b) ? 1 : ((a > b) ? -1 : 0));

what the heck is the equivalent in C#?

I thought it might be

int x = ((a > b) ? 1 : ((a < b) ? -1 : 0));

I would like someone who knows for certain to confirm.

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by DaveTran
1

In C++ the ternary operator below will return 1.

true ? 0 : 1

In C# it will return 0.

You need to recheck that, it returns 0 in C, C++ and C#.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.