Solved

C# return query

Posted on 2006-11-06
2
244 Views
Last Modified: 2010-04-16
I have noticed the use of this code in an application that I am developing can anybody tell me what it means when you have the ? and :

ie return (returnValue == 0 ? true : false);

Does it act like an if else statement??

Many thanks

Cragly
0
Comment
Question by:Cragly
2 Comments
 
LVL 13

Accepted Solution

by:
AngryBinary earned 500 total points
ID: 17881835
This is an abbreviated conditional syntax. The expression preceding the question mark is evaluated. If it is true, the expression preceding the colon is returned. Otherwise, the expression following the colon is returned. In other words,

return (returnValue == 0 ? true : false)

is the same as

if (returnValue == 0) {
    return true;
} else {
    return false;
}

Incidentally, this expression is mildly redundant, especially considering that this abbreviated syntax slightly reduces the codes readability. Even though I would consider the 'if/else' to be the preferred syntax, since it is easier to read, an equivalent shorthand expression would be:

return (returnValue == 0);

which would return true or false, depending on the value of returnValue.

Cheers,
Randall
0
 

Author Comment

by:Cragly
ID: 17881994
Cheers many thanks for your help
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

948 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now