Advertisement

07.14.2008 at 10:08PM PDT, ID: 23565037
[x]
Attachment Details

C# Question mark (The ternary operator)

Asked by mmexchange in Microsoft Visual C#.Net, Visual Studio 2008

I'm trying to use the ternary operator to do the following:
int nRetValue;
// Do some stuff
(nRetValue == 1) ? MyCt1++ : MyCt2++;

This doesn't work, why?
(I want to increment MyCt1 if nRetValue == 1, otherwise increment MyCt2)
I know how to do it with if (...) ... but shouldn't this work?Start Free Trial
[+][-]07.14.2008 at 10:13PM PDT, ID: 22004282

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.14.2008 at 10:14PM PDT, ID: 22004285

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Microsoft Visual C#.Net, Visual Studio 2008
Sign Up Now!
Solution Provided By: angelIII
Participating Experts: 2
Solution Grade: A
 
 
[+][-]07.14.2008 at 10:19PM PDT, ID: 22004304

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628