Results 1 to 6 of 6

Thread: How does ?: Conditional operator in C# operate

  1. #1
    Join Date
    Dec 2010
    Posts
    66

    How does ?: Conditional operator in C# operate

    I am a student on IT student studying in a well reputed college in mumbai. My graduation course comprises of six semesters and I have to clear each semester with 50 % marks in each and every semester , if I fail in any of the two subjects i.e score less than 50% of marks in any two subjects then I will not be promoted to the next year. I have learned and memorized all the the subjects but I am quite concerned about the C# language , I am quite weak at it , and I am quite weak in the Conditional operators. I just wanted to know about the ?: Conditional operator in C# and about their operation , I will be so glad if any developer or programmer comments on this.

  2. #2
    Join Date
    May 2009
    Posts
    529

    Re: How does ?: Conditional operator in C# operate

    The ?: operator is known as the conditional operator. It is sometime also known as the ternary operator. It normally comprises of
    conditional-expression: and along with that it contains null-coalescing-expression it can be expressed as given below
    • null-coalescing-expression ? expression : expression

    If there is any conditional expression then it can be in the form b ? x : y first calculates the condition b. Then, checks if b is true, x is calculated and becomes the answer of the expression. or else, y is calculated and becomes the answer of the expression. A conditional expression never calculates both x and y. This operators can thus be used in case of if-else statements.

  3. #3
    Join Date
    Apr 2009
    Posts
    569

    Re: How does ?: Conditional operator in C# operate

    The conditional operator is right-associative, that implies that expressions are arrayed from in the order from right to left. [for instance : An expression of the form m ? n : o ? p : q is evaluated as m ? n : (o ? p : q).
    The initial operand of the ?: operator should be an expression of a sort that can be completely converted to a data type bool, or an expression of a kind that implements operator true. If none of these necessities is fulfilled, a compile-time error will be encountered.

  4. #4
    Join Date
    May 2009
    Posts
    511

    Re: How does ?: Conditional operator in C# operate

    In this types of operators, the second and third operands of the ?: operator manage the kind of the conditional operation. Let X and Y be the types of the second and third operands. Then,
    • If X and Y are the same kind, then this is the type of the conditional operator.
    • Otherwise, if an implicit conversion is there from X to Y, but it is not present in the opposite manner , then Y is the sort of the conditional operation .
    • A the above situation once again if there is any sort of implicit conversion from Y to X, but not in the reverse order , then X is the kind of the conditional operation.
    • If none if these happens no expression type can be calculated , and a compile-time error is encountered.

  5. #5
    Join Date
    May 2009
    Posts
    527

    Re: How does ?: Conditional operator in C# operate

    The run-time executing of a conditional operation of the form b ? x : y comprise of the following steps:
    • First, b is calculated , and the bool value of b is evaluated
      • If an implicit casting from the datatype of b to bool persists, then this sort of conversion is completed to generate a bool value.
      • o Or else , the operator true defined by the kind of b is called to generate a bool value.


  6. #6
    Join Date
    May 2009
    Posts
    637

    Re: How does ?: Conditional operator in C# operate

    Considering the above example :
    • If the bool value created by the step you have mentioned above is true, then x is calculated and converted to the sort of the conditional expression, and this becomes the answer of the conditional expression.
    • Or else , y is estimated and converted to the type of the conditional operation, and this results in the answer of the conditional operation.

Similar Threads

  1. How to operate Nokia 1208 with no SIM
    By Victorious in forum Portable Devices
    Replies: 4
    Last Post: 14-01-2011, 06:55 AM
  2. How to operate two operating system in one pc.
    By quentein in forum Operating Systems
    Replies: 3
    Last Post: 16-11-2010, 04:53 AM
  3. Can't iPad operate with no Mac or PC connecting?
    By Lyandon in forum Portable Devices
    Replies: 4
    Last Post: 04-10-2010, 10:31 PM
  4. iMac too slow to operate
    By OS-X-10+ in forum Operating Systems
    Replies: 3
    Last Post: 06-10-2009, 12:55 PM
  5. W-lan offline network operate?
    By Wahib in forum Networking & Security
    Replies: 3
    Last Post: 18-03-2009, 01:39 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,205,989.37884 seconds with 17 queries