473,325 Members | 2,308 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

'Inline IF' Statement??

Hi,

Someone once showed me a C# statement that worked like:

myInt = (if <some condition>then 3 otherwise 4)

The syntax is totally wrong, (that's what I'm trying to remember). But it
worked like that.

He called it a 'Unary If' statement (or somthing like that)

ie I could assign either 3 or 4 to my integer variable myInt depending on
the evalutaion of the condition.

To put it another way, it was the equivelent of

if (<some condition>)
myInt = 3
else
myInt = 4

but in a single statement.

Does anyone know what the hell I'm talking about?
Nov 15 '05 #1
3 154355
Yes.

The syntax is "myInt = (<condition> ? <true value> : <false value>)"

"ChrisM" <hi****@AskMeIfYouWantIt.com> wrote in message
news:eg****************@TK2MSFTNGP12.phx.gbl...
Hi,

Someone once showed me a C# statement that worked like:

myInt = (if <some condition>then 3 otherwise 4)

The syntax is totally wrong, (that's what I'm trying to remember). But it
worked like that.

He called it a 'Unary If' statement (or somthing like that)

ie I could assign either 3 or 4 to my integer variable myInt depending on
the evalutaion of the condition.

To put it another way, it was the equivelent of

if (<some condition>)
myInt = 3
else
myInt = 4

but in a single statement.

Does anyone know what the hell I'm talking about?

Nov 15 '05 #2
ChrisM <hi****@AskMeIfYouWantIt.com> wrote:
Someone once showed me a C# statement that worked like:

myInt = (if <some condition>then 3 otherwise 4)

The syntax is totally wrong, (that's what I'm trying to remember). But it
worked like that.

He called it a 'Unary If' statement (or somthing like that)

ie I could assign either 3 or 4 to my integer variable myInt depending on
the evalutaion of the condition.

To put it another way, it was the equivelent of

if (<some condition>)
myInt = 3
else
myInt = 4

but in a single statement.

Does anyone know what the hell I'm talking about?


Yes - I believe you're talking about the conditional operator:

myInt = condition ? 3 : 4;

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #3
Peter/Jon

Thats the baby.

Thanks Guys!

ChrisM
"ChrisM" <hi****@AskMeIfYouWantIt.com> wrote in message
news:eg****************@TK2MSFTNGP12.phx.gbl...
Hi,

Someone once showed me a C# statement that worked like:

myInt = (if <some condition>then 3 otherwise 4)

The syntax is totally wrong, (that's what I'm trying to remember). But it
worked like that.

He called it a 'Unary If' statement (or somthing like that)

ie I could assign either 3 or 4 to my integer variable myInt depending on
the evalutaion of the condition.

To put it another way, it was the equivelent of

if (<some condition>)
myInt = 3
else
myInt = 4

but in a single statement.

Does anyone know what the hell I'm talking about?

Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: A | last post by:
Hi, I'm having problems completing a project in C++. I have been using inline functions in some of my header files. I have only done so for simple functions that only have 1 statement (eg....
4
by: Surendra | last post by:
I have this query that I need to use in an Update statement to populate a field in the table by the value of Sq ---------------------------------------------------------------------------- Inline...
10
by: yawnmoth | last post by:
http://www.frostjedi.com/terra/dev/test.html I'd like to have the colored boxes appear on the same line as "Test" does. The div containing the colored boxes is defined as being inline, yet...
43
by: Patrick Laurent | last post by:
Hello I have a program with many many inlined template functions It is essential for the execution speed that every (or almost every) function marked as inlined, becomes really inlined by the...
6
by: John Ratliff | last post by:
I was reading the C++ FAQ Lite about inline functions, and it says the following (http://www.parashift.com/c++-faq-lite/inline-functions.html#faq-9.7) " It's usually imperative that the...
33
by: Robert Seacord | last post by:
When writing C99 code is a reasonable recommendation to use inline functions instead of macros? What sort of things is it still reasonable to do using macros? For example, is it reasonable to...
12
by: sam_cit | last post by:
Hi Everyone, I have few questions on inline functions, when i declare a function as inline, is it for sure that the compiler would replace the function call with the actual body of the function?...
2
by: aaragon | last post by:
Hi everyone, I would like to create a very simple function: // header file inline void point_map() { PointMap pointMap = get(vertex_point_t(), g); } // main.cpp
0
by: feeblemind | last post by:
Hi everyone, I am having problem/troubles with creating an sql inline statement for our application. How do I create a statement/query that selects list of servers with defined date ranges, but...
37
by: Prisoner at War | last post by:
Actually, it doesn't have to be a blockquote...but I'm at my wits' end: I want to make bold several lines of text which have a pair of <br /tags between them...seems like the <b></bdo not "carry...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.