Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. ? : Operator

? : Operator

Scheduled Pinned Locked Moved C#
questioncsharphtmlcomhelp
15 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Luc Pattyn

    everything you should know about C# is in your C# book, in MSDN, in the C# specification[^], etc. :|

    Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

    Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

    L Offline
    L Offline
    Lost User
    wrote on last edited by
    #5

    Thank you , But for a certain things MSDN is Yak ! http://msdn.microsoft.com/en-us/library/ty67wk28.aspx[^] The conditional operator is right-associative. The expression a ? b : c ? d : e is evaluated as a ? b : (c ? d : e), not as (a ? b : c) ? d : e. The conditional operator cannot be overloaded. X|

    I know nothing , I know nothing ...

    R L D 3 Replies Last reply
    0
    • L Lost User

      It means

      if (b == null)
      a = null;
      else
      a = a.ToString(); //this rarely makes sense, didn't you mean b.ToString()?

      But it's an expression instead of a statement.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #6

      And yes I meant b.toString(); :)

      I know nothing , I know nothing ...

      1 Reply Last reply
      0
      • L Lost User

        Thank you so much , for this fast , great replay of yours , you saved me from headache :doh: I have voted for you :rose:

        I know nothing , I know nothing ...

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #7

        Thanks :thumbsup:

        1 Reply Last reply
        0
        • L Lost User

          Thank you , But for a certain things MSDN is Yak ! http://msdn.microsoft.com/en-us/library/ty67wk28.aspx[^] The conditional operator is right-associative. The expression a ? b : c ? d : e is evaluated as a ? b : (c ? d : e), not as (a ? b : c) ? d : e. The conditional operator cannot be overloaded. X|

          I know nothing , I know nothing ...

          R Offline
          R Offline
          Roger Wright
          wrote on last edited by
          #8

          You're right, and that's classic Microsoft - technically accurate, entirely useless information! :laugh:

          "A Journey of a Thousand Rest Stops Begins with a Single Movement"

          L 1 Reply Last reply
          0
          • R Roger Wright

            You're right, and that's classic Microsoft - technically accurate, entirely useless information! :laugh:

            "A Journey of a Thousand Rest Stops Begins with a Single Movement"

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #9

            "you're in an airplane" kind of stuff? :)

            Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

            Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

            R 1 Reply Last reply
            0
            • L Luc Pattyn

              "you're in an airplane" kind of stuff? :)

              Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

              Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

              R Offline
              R Offline
              Roger Wright
              wrote on last edited by
              #10

              Exactly! :-D

              "A Journey of a Thousand Rest Stops Begins with a Single Movement"

              1 Reply Last reply
              0
              • L Lost User

                Thank you , But for a certain things MSDN is Yak ! http://msdn.microsoft.com/en-us/library/ty67wk28.aspx[^] The conditional operator is right-associative. The expression a ? b : c ? d : e is evaluated as a ? b : (c ? d : e), not as (a ? b : c) ? d : e. The conditional operator cannot be overloaded. X|

                I know nothing , I know nothing ...

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #11

                Where is the Yak point? In all fairness, the first line of the document states;

                The conditional operator (?:) returns one of two values depending on the value of a Boolean expression.

                Perfect logical KISS.

                I are Troll :suss:

                1 Reply Last reply
                0
                • L Lost User

                  Thank you , But for a certain things MSDN is Yak ! http://msdn.microsoft.com/en-us/library/ty67wk28.aspx[^] The conditional operator is right-associative. The expression a ? b : c ? d : e is evaluated as a ? b : (c ? d : e), not as (a ? b : c) ? d : e. The conditional operator cannot be overloaded. X|

                  I know nothing , I know nothing ...

                  D Offline
                  D Offline
                  dan sh
                  wrote on last edited by
                  #12

                  I do not understand why you think like that.

                  1 Reply Last reply
                  0
                  • L Lost User

                    Hi , have a good day Can anyone Explain for me what the meaning of this ?

                    a = b == null ? null : a.ToString();

                    P.S : for more information : I use this component Example Code , and I need to understand it ! http://www.gemboxsoftware.com/help/html/M_GemBox_Spreadsheet_ExcelWorksheet_ExtractToDataTable.htm[^]

                    if (e.ErrorID == ExtractDataError.WrongType)
                    {
                    e.DataTableValue = e.ExcelValue == null ? null : e.ExcelValue.ToString();
                    e.Action = ExtractDataEventAction.Continue;
                    }

                    Please , Don't tell to Ask at Component Forum , due my question is C# syntax things thank you

                    I know nothing , I know nothing ...

                    D Offline
                    D Offline
                    dan sh
                    wrote on last edited by
                    #13

                    I guess you meant b.ToString there. If you did, you really don't need ternary operator. Convert.ToString would be enough.

                    1 Reply Last reply
                    0
                    • L Lost User

                      Hi , have a good day Can anyone Explain for me what the meaning of this ?

                      a = b == null ? null : a.ToString();

                      P.S : for more information : I use this component Example Code , and I need to understand it ! http://www.gemboxsoftware.com/help/html/M_GemBox_Spreadsheet_ExcelWorksheet_ExtractToDataTable.htm[^]

                      if (e.ErrorID == ExtractDataError.WrongType)
                      {
                      e.DataTableValue = e.ExcelValue == null ? null : e.ExcelValue.ToString();
                      e.Action = ExtractDataEventAction.Continue;
                      }

                      Please , Don't tell to Ask at Component Forum , due my question is C# syntax things thank you

                      I know nothing , I know nothing ...

                      Y Offline
                      Y Offline
                      yu jian
                      wrote on last edited by
                      #14

                      a = b == null ? null : a.ToString(); Means if b equals null then set a = null else set a = a.ToString() if code changed to following, I may understand it. if (b == null) { a = null; } else { a = a.toString() }

                      1 Reply Last reply
                      0
                      • L Lost User

                        Hi , have a good day Can anyone Explain for me what the meaning of this ?

                        a = b == null ? null : a.ToString();

                        P.S : for more information : I use this component Example Code , and I need to understand it ! http://www.gemboxsoftware.com/help/html/M_GemBox_Spreadsheet_ExcelWorksheet_ExtractToDataTable.htm[^]

                        if (e.ErrorID == ExtractDataError.WrongType)
                        {
                        e.DataTableValue = e.ExcelValue == null ? null : e.ExcelValue.ToString();
                        e.Action = ExtractDataEventAction.Continue;
                        }

                        Please , Don't tell to Ask at Component Forum , due my question is C# syntax things thank you

                        I know nothing , I know nothing ...

                        B Offline
                        B Offline
                        brunoseixas
                        wrote on last edited by
                        #15

                        ? operator its like a IF-result statement. look:

                        int x = 0;
                        int y = 1;

                        if(x > y) ? y++ : y--;

                        If x>y = true, y++.
                        If x>y = false, y--;

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups