Results 1 to 6 of 6

Thread: [RESOLVED] ? Operator

  1. #1

    Thread Starter
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,711

    Resolved [RESOLVED] ? Operator

    Is the ? operator the same as the If operator in VB.Net?

    IE - Does this:
    Code:
    Dim foo As Integer = If(1 = 2, 5, 10)
    'Foo = 10
    Translate to this:
    Code:
    int foo = (1 == 2) ? 5 : 10;
    //Foo = 10
    Last edited by dday9; Apr 16th, 2015 at 11:18 AM.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  2. #2
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: ? Operator

    That's a condensed if in Java. It looks like it is the same as in VB, but just in case, it is doing:

    <if whatever> ? <then> : <else>

  3. #3

    Thread Starter
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,711

    Re: ? Operator

    Ok, that's what I figured. Thanks!
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  4. #4
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: [RESOLVED] ? Operator

    "Condensed if" is made up terminology. Just see https://en.wikipedia.org/wiki/%3F:#Java for the skinny in brief.

  5. #5
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: [RESOLVED] ? Operator

    While condensed if may be made up terminology, if 90% of programmers use the term, it is correct to use when describing something. It's the exact reason something gets added to the dictionary -- common use.

    Just like no one will know what you're talking about if you pronounce the .gif file extension as "jif."

  6. #6
    Fanatic Member Toph's Avatar
    Join Date
    Oct 2014
    Posts
    655

    Re: [RESOLVED] ? Operator

    I know I'm a bit late. But this is called a Ternary operator.
    If you find my contributions helpful then rate them.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width