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.

Recommended Answers

All 2 Replies

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#.

Ah yes, sorry.

The problem must be something else... :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.