2 Replies - 650 Views - Last Post: 03 September 2008 - 06:09 PM Rate Topic: -----

#1 gbertoli3  Icon User is offline

  • DIC at Heart + Code
  • member icon

Reputation: 40
  • View blog
  • Posts: 1,162
  • Joined: 23-June 08

Characters

Posted 03 September 2008 - 05:50 PM

What are the ? and the | characters use for?

In PsychoCoder's snippet on Finding Text in a RichTextBox he used the ? character.

Here is a line of code taken from his snippet
type = matchCase == true ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase;

In PsychoCoder's tutorial on Disabling An Applications Close Button he used the | character.

Here is a line of code taken from his tutorial.
RemoveMenu(menu, itemCount - 1, disable | remove);

Thanks

Is This A Good Question/Topic? 0
  • +

Replies To: Characters

#2 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Characters

Posted 03 September 2008 - 06:07 PM

The ? is called a Conditional Operator, also known as ternary operator. It is short hand for an If/Else statement. On the left side is the condition that is evaluated. PsychoCoder is actually performing two operations on the left side.

First he is assigning the value stored in matchCase into the type variable. The second operation he is comparing the value stored in matchCase to "true".

On the right side of the conditional operator (?), these are the If/Else branches, they are seperated by a :. IF the condition evaluates to true, then StringComparison.Ordinal will be the code that executes, : ELSE the condition is false and StringComparison.OrdinalIgnoreCase will execute.

Conditional Operator

As for the second question, that is a logical OR operator, or depending on how it is used, the bitwise OR operator.
| Operator.
Was This Post Helpful? 0
  • +
  • -

#3 gbertoli3  Icon User is offline

  • DIC at Heart + Code
  • member icon

Reputation: 40
  • View blog
  • Posts: 1,162
  • Joined: 23-June 08

Re: Characters

Posted 03 September 2008 - 06:09 PM

Thanks, I didn't know programming had short hand.

This post has been edited by gbertoli3: 03 September 2008 - 06:12 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1