Solved

C# return query

Posted on 2006-11-06
2
276 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
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…
Simple Linear Regression
Introduction to Processes

636 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