Solved

C# return query

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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Recommendation vb6 to vb.net or others 14 201
Full Screen problem when auto scale IFRAME 2 119
storing csv file in table variable in Python 2 58
Survey branching tutorial 11 38
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

713 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