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. The Lounge
  3. C# syntax quiz [modified*2]

C# syntax quiz [modified*2]

Scheduled Pinned Locked Moved The Lounge
questioncsharp
22 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.
  • D Daniel Grunwald

    If you have a valid C# program (valid=compiles without errors), can the removal of a space between two non-keyword operators cause the program to no longer compile / behave differently? (behave different is solved by Rama Krishna Vavilala and PIEBALDconsult - now try to break compilation without using unary operators) E.g. removing the space between "< =" changes it from two tokens into the combined "<=" token that has different meaning. But this is not a solution to the question because there is no valid C# program that contains "< =". Is there a combination of two non-keyword non-identifier tokens that is makes a valid program with a space in between but breaks when you remove the space?


    Last modified: 26mins after originally posted --

    P Online
    P Online
    PIEBALDconsult
    wrote on last edited by
    #2

    Dang, I think I've seen this one before, I'm pretty sure the answer is "yes", but I don't remember what the syntax is.

    1 Reply Last reply
    0
    • D Daniel Grunwald

      If you have a valid C# program (valid=compiles without errors), can the removal of a space between two non-keyword operators cause the program to no longer compile / behave differently? (behave different is solved by Rama Krishna Vavilala and PIEBALDconsult - now try to break compilation without using unary operators) E.g. removing the space between "< =" changes it from two tokens into the combined "<=" token that has different meaning. But this is not a solution to the question because there is no valid C# program that contains "< =". Is there a combination of two non-keyword non-identifier tokens that is makes a valid program with a space in between but breaks when you remove the space?


      Last modified: 26mins after originally posted --

      E Offline
      E Offline
      Ennis Ray Lynch Jr
      wrote on last edited by
      #3

      string abc = "\u12 345";


      File Not Found

      D 1 Reply Last reply
      0
      • D Daniel Grunwald

        If you have a valid C# program (valid=compiles without errors), can the removal of a space between two non-keyword operators cause the program to no longer compile / behave differently? (behave different is solved by Rama Krishna Vavilala and PIEBALDconsult - now try to break compilation without using unary operators) E.g. removing the space between "< =" changes it from two tokens into the combined "<=" token that has different meaning. But this is not a solution to the question because there is no valid C# program that contains "< =". Is there a combination of two non-keyword non-identifier tokens that is makes a valid program with a space in between but breaks when you remove the space?


        Last modified: 26mins after originally posted --

        R Offline
        R Offline
        Rama Krishna Vavilala
        wrote on last edited by
        #4

        How about this:

        int i = 0;
        int j = 1;
        i =+ +j;

        Space i = 1, Remove the space i = 2.

        Co-Author ASP.NET AJAX in Action

        D 1 Reply Last reply
        0
        • D Daniel Grunwald

          If you have a valid C# program (valid=compiles without errors), can the removal of a space between two non-keyword operators cause the program to no longer compile / behave differently? (behave different is solved by Rama Krishna Vavilala and PIEBALDconsult - now try to break compilation without using unary operators) E.g. removing the space between "< =" changes it from two tokens into the combined "<=" token that has different meaning. But this is not a solution to the question because there is no valid C# program that contains "< =". Is there a combination of two non-keyword non-identifier tokens that is makes a valid program with a space in between but breaks when you remove the space?


          Last modified: 26mins after originally posted --

          P Online
          P Online
          PIEBALDconsult
          wrote on last edited by
          #5

          x = y - -5 ; x = y --5 ;

          1 Reply Last reply
          0
          • R Rama Krishna Vavilala

            How about this:

            int i = 0;
            int j = 1;
            i =+ +j;

            Space i = 1, Remove the space i = 2.

            Co-Author ASP.NET AJAX in Action

            D Offline
            D Offline
            Daniel Grunwald
            wrote on last edited by
            #6

            Correct. I was looking for a different solution, try something that doesn't use unary operators.

            1 Reply Last reply
            0
            • E Ennis Ray Lynch Jr

              string abc = "\u12 345";


              File Not Found

              D Offline
              D Offline
              Daniel Grunwald
              wrote on last edited by
              #7

              "\u12 345" is a single string literal token; removing the space changes the string value but does not combine any tokens. I'm looking for something that combined produces an operator.

              1 Reply Last reply
              0
              • D Daniel Grunwald

                If you have a valid C# program (valid=compiles without errors), can the removal of a space between two non-keyword operators cause the program to no longer compile / behave differently? (behave different is solved by Rama Krishna Vavilala and PIEBALDconsult - now try to break compilation without using unary operators) E.g. removing the space between "< =" changes it from two tokens into the combined "<=" token that has different meaning. But this is not a solution to the question because there is no valid C# program that contains "< =". Is there a combination of two non-keyword non-identifier tokens that is makes a valid program with a space in between but breaks when you remove the space?


                Last modified: 26mins after originally posted --

                E Offline
                E Offline
                Ennis Ray Lynch Jr
                wrote on last edited by
                #8

                public class Foo{ public static void SomeMethod(){ Foo bar; } }


                File Not Found

                D 1 Reply Last reply
                0
                • D Daniel Grunwald

                  If you have a valid C# program (valid=compiles without errors), can the removal of a space between two non-keyword operators cause the program to no longer compile / behave differently? (behave different is solved by Rama Krishna Vavilala and PIEBALDconsult - now try to break compilation without using unary operators) E.g. removing the space between "< =" changes it from two tokens into the combined "<=" token that has different meaning. But this is not a solution to the question because there is no valid C# program that contains "< =". Is there a combination of two non-keyword non-identifier tokens that is makes a valid program with a space in between but breaks when you remove the space?


                  Last modified: 26mins after originally posted --

                  L Offline
                  L Offline
                  lost in transition
                  wrote on last edited by
                  #9

                  while (0 = = 0) { Foobie; }


                  God Bless, Jason
                  God doesn't believe in atheist but He still loves them.

                  D 1 Reply Last reply
                  0
                  • E Ennis Ray Lynch Jr

                    public class Foo{ public static void SomeMethod(){ Foo bar; } }


                    File Not Found

                    D Offline
                    D Offline
                    Daniel Grunwald
                    wrote on last edited by
                    #10

                    Foobar still isn't an operator. Somewhat correct because I wrote "non-keyword token" where I really meant "non-keyword non-literal non-identifier" (=operator) token.

                    1 Reply Last reply
                    0
                    • L lost in transition

                      while (0 = = 0) { Foobie; }


                      God Bless, Jason
                      God doesn't believe in atheist but He still loves them.

                      D Offline
                      D Offline
                      Daniel Grunwald
                      wrote on last edited by
                      #11

                      The code must compile before removing the space.

                      L 1 Reply Last reply
                      0
                      • D Daniel Grunwald

                        If you have a valid C# program (valid=compiles without errors), can the removal of a space between two non-keyword operators cause the program to no longer compile / behave differently? (behave different is solved by Rama Krishna Vavilala and PIEBALDconsult - now try to break compilation without using unary operators) E.g. removing the space between "< =" changes it from two tokens into the combined "<=" token that has different meaning. But this is not a solution to the question because there is no valid C# program that contains "< =". Is there a combination of two non-keyword non-identifier tokens that is makes a valid program with a space in between but breaks when you remove the space?


                        Last modified: 26mins after originally posted --

                        E Offline
                        E Offline
                        Ennis Ray Lynch Jr
                        wrote on last edited by
                        #12

                        csc *.cs


                        File Not Found

                        1 Reply Last reply
                        0
                        • D Daniel Grunwald

                          The code must compile before removing the space.

                          L Offline
                          L Offline
                          lost in transition
                          wrote on last edited by
                          #13

                          To compile or not compile that is the question isn't it. Let us evaluate the situation, how does you mother make you feel?:sigh:


                          God Bless, Jason
                          God doesn't believe in atheist but He still loves them.

                          1 Reply Last reply
                          0
                          • D Daniel Grunwald

                            If you have a valid C# program (valid=compiles without errors), can the removal of a space between two non-keyword operators cause the program to no longer compile / behave differently? (behave different is solved by Rama Krishna Vavilala and PIEBALDconsult - now try to break compilation without using unary operators) E.g. removing the space between "< =" changes it from two tokens into the combined "<=" token that has different meaning. But this is not a solution to the question because there is no valid C# program that contains "< =". Is there a combination of two non-keyword non-identifier tokens that is makes a valid program with a space in between but breaks when you remove the space?


                            Last modified: 26mins after originally posted --

                            M Offline
                            M Offline
                            Mladen Jankovic
                            wrote on last edited by
                            #14

                            Maybe: G1<G2<int> > collection; I know that this makes trouble if you remove space between > > on some C++ compilers, and I read somewhere that they changed parser and lexer in C# to solve this problem. Ok I found the source: C# 2.0 specification, so my answer is valid only for C# 1.0 :)

                            Mostly, when you see programmers, they aren't doing anything. One of the attractive things about programmers is that you cannot tell whether or not they are working simply by looking at them. Very often they're sitting there seemingly drinking coffee and gossiping, or just staring into space. What the programmer is trying to do is get a handle on all the individual and unrelated ideas that are scampering around in his head. (Charles M Strauss)

                            D 1 Reply Last reply
                            0
                            • M Mladen Jankovic

                              Maybe: G1<G2<int> > collection; I know that this makes trouble if you remove space between > > on some C++ compilers, and I read somewhere that they changed parser and lexer in C# to solve this problem. Ok I found the source: C# 2.0 specification, so my answer is valid only for C# 1.0 :)

                              Mostly, when you see programmers, they aren't doing anything. One of the attractive things about programmers is that you cannot tell whether or not they are working simply by looking at them. Very often they're sitting there seemingly drinking coffee and gossiping, or just staring into space. What the programmer is trying to do is get a handle on all the individual and unrelated ideas that are scampering around in his head. (Charles M Strauss)

                              D Offline
                              D Offline
                              Daniel Grunwald
                              wrote on last edited by
                              #15

                              C# is not C++ - generics in C# work the same both with > > and >>. And AFAIK the next C++ standard will specify how compilers should distinguish the shift operator from two > without requiring that ugly space.

                              M 1 Reply Last reply
                              0
                              • D Daniel Grunwald

                                C# is not C++ - generics in C# work the same both with > > and >>. And AFAIK the next C++ standard will specify how compilers should distinguish the shift operator from two > without requiring that ugly space.

                                M Offline
                                M Offline
                                Mladen Jankovic
                                wrote on last edited by
                                #16

                                C# 2.0 spec:

                                The syntax for generics uses the < and > characters to delimit type parameters and type arguments (similar to the syntax used in C++ for templates). Constructed types sometimes nest, as in List<Nullable<int>>, but there is a subtle grammatical problem with such constructs: the lexical grammar will combine the last two characters of this construct into the single token >> (the right shift operator), rather than producing two > tokens, which the syntactic grammar would require. Although a possible solution is to put a space in between the two > characters, this is awkward and confusing, and does not add to the clarity of the program in any way.

                                So IMHO, as I said, C# _1.0_ had this problem.

                                Mostly, when you see programmers, they aren't doing anything. One of the attractive things about programmers is that you cannot tell whether or not they are working simply by looking at them. Very often they're sitting there seemingly drinking coffee and gossiping, or just staring into space. What the programmer is trying to do is get a handle on all the individual and unrelated ideas that are scampering around in his head. (Charles M Strauss)

                                P 1 Reply Last reply
                                0
                                • M Mladen Jankovic

                                  C# 2.0 spec:

                                  The syntax for generics uses the < and > characters to delimit type parameters and type arguments (similar to the syntax used in C++ for templates). Constructed types sometimes nest, as in List<Nullable<int>>, but there is a subtle grammatical problem with such constructs: the lexical grammar will combine the last two characters of this construct into the single token >> (the right shift operator), rather than producing two > tokens, which the syntactic grammar would require. Although a possible solution is to put a space in between the two > characters, this is awkward and confusing, and does not add to the clarity of the program in any way.

                                  So IMHO, as I said, C# _1.0_ had this problem.

                                  Mostly, when you see programmers, they aren't doing anything. One of the attractive things about programmers is that you cannot tell whether or not they are working simply by looking at them. Very often they're sitting there seemingly drinking coffee and gossiping, or just staring into space. What the programmer is trying to do is get a handle on all the individual and unrelated ideas that are scampering around in his head. (Charles M Strauss)

                                  P Online
                                  P Online
                                  PIEBALDconsult
                                  wrote on last edited by
                                  #17

                                  Those wouldn't be operators anyway would they? They're delimiters or something in that usage. -- modified at 17:25 Friday 24th August, 2007 Huh, the documentation just says " client code must declare and instantiate a constructed type by specifying a type argument inside the angle brackets. " So I guess Microsoft doesn't know what to call them anyway.

                                  D 1 Reply Last reply
                                  0
                                  • P PIEBALDconsult

                                    Those wouldn't be operators anyway would they? They're delimiters or something in that usage. -- modified at 17:25 Friday 24th August, 2007 Huh, the documentation just says " client code must declare and instantiate a constructed type by specifying a type argument inside the angle brackets. " So I guess Microsoft doesn't know what to call them anyway.

                                    D Offline
                                    D Offline
                                    Daniel Grunwald
                                    wrote on last edited by
                                    #18

                                    Well, I consider them operator tokens as a standalone ">" is a greater-than operator. Lexical analysis only produces tokens, what's an operator and what isn't can change based on the context they are used in - so strictly speaking there no such thing as an operator token. (that's why I wrote "non-keyword non-identifier non-literal"). "< <" is never valid, "> >" only for generics where it is the same as ">>". So those are not solutions. Hint: in the solution I'm looking for, the same character is used twice with a space in between, but the first instance has a totally different meaning than the second (only the second is a real operator). Without the space, they produce yet another operator.

                                    1 Reply Last reply
                                    0
                                    • D Daniel Grunwald

                                      If you have a valid C# program (valid=compiles without errors), can the removal of a space between two non-keyword operators cause the program to no longer compile / behave differently? (behave different is solved by Rama Krishna Vavilala and PIEBALDconsult - now try to break compilation without using unary operators) E.g. removing the space between "< =" changes it from two tokens into the combined "<=" token that has different meaning. But this is not a solution to the question because there is no valid C# program that contains "< =". Is there a combination of two non-keyword non-identifier tokens that is makes a valid program with a space in between but breaks when you remove the space?


                                      Last modified: 26mins after originally posted --

                                      D Offline
                                      D Offline
                                      Daniel Grunwald
                                      wrote on last edited by
                                      #19

                                      It's easy with unary plus/minus <-> increment/decrement:

                                      i =+ +j;
                                      x = y - -5 ;

                                      But there is another solution that's much more difficult to find:

                                      object o = null;
                                      string text = o is int ? ? "o is Nullable" : "o is not Nullable";

                                      Removing the space between the question marks causes them to become the null-coalescing operator ??, and you get a syntax error at the ':'.

                                      P 2 Replies Last reply
                                      0
                                      • D Daniel Grunwald

                                        It's easy with unary plus/minus <-> increment/decrement:

                                        i =+ +j;
                                        x = y - -5 ;

                                        But there is another solution that's much more difficult to find:

                                        object o = null;
                                        string text = o is int ? ? "o is Nullable" : "o is not Nullable";

                                        Removing the space between the question marks causes them to become the null-coalescing operator ??, and you get a syntax error at the ':'.

                                        P Online
                                        P Online
                                        PIEBALDconsult
                                        wrote on last edited by
                                        #20

                                        Daniel Grunwald wrote:

                                        i =+ +j;

                                        What's that? It's not +=

                                        D 1 Reply Last reply
                                        0
                                        • P PIEBALDconsult

                                          Daniel Grunwald wrote:

                                          i =+ +j;

                                          What's that? It's not +=

                                          D Offline
                                          D Offline
                                          Daniel Grunwald
                                          wrote on last edited by
                                          #21

                                          "i =+ +j;" is the same as "i = +(+j);" - it's using the unary plus operator two times.

                                          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