Solved

C# return query

Posted on 2006-11-06
2
230 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
A short article about a problem I had getting the GPS LocationListener working.
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 …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

706 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