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. So how well do you think you know C#?

So how well do you think you know C#?

Scheduled Pinned Locked Moved The Lounge
csharpphpvisual-studiocomquestion
37 Posts 20 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.
  • J Jorgen Sigvardsson

    Your sig... ;)

    M Offline
    M Offline
    Mustafa Ismail Mustafa
    wrote on last edited by
    #12

    :doh: :laugh:

    Don't forget to vote if the response was helpful


    Sig history "dad" Ishmail-Samuel Mustafa "You're an idiot." John Simmons, THE Outlaw programmer "I realised that all of my best anecdotes started with "So there we were, pissed". Pete O'Hanlon Unix is a Four Letter Word, and Vi is a Two Letter Abbreviation

    1 Reply Last reply
    0
    • M Mustafa Ismail Mustafa

      double, and I'd be surprised if it were anything else...

      Don't forget to vote if the response was helpful


      Sig history "dad" Ishmail-Samuel Mustafa "You're an idiot." John Simmons, THE Outlaw programmer "I realised that all of my best anecdotes started with "So there we were, pissed". Pete O'Hanlon Unix is a Four Letter Word, and Vi is a Two Letter Abbreviation

      G Offline
      G Offline
      Gary Wheeler
      wrote on last edited by
      #13

      Mustafa Ismail Mustafa wrote:

      double, and I'd be surprised if it were anything else...

      double, and I'd be surprised pissed off if it were anything else... (I'm in the process of learning C#)

      Software Zen: delete this;

      M 1 Reply Last reply
      0
      • L leppie

        Without compiling the following code, what will be the result, if run?

        class Program
        {
        static void Main(string[] args)
        {
        object r = Foo(true);
        Console.WriteLine(r.GetType());
        Console.ReadLine();
        }

        static object Foo(bool e)
        {
        return e ? 0 : 0.0;
        }
        }

        Now compile and run the code? Are you surprised? If so, try figure it out, if not, then kudos to you :)

        xacc.ide - now with TabsToSpaces support
        IronScheme - 1.0 alpha 4a out now (29 May 2008)

        R Offline
        R Offline
        Rajesh R Subramanian
        wrote on last edited by
        #14

        How do you get formatted and colorised code like that? Is there a tool or something? Do you mind sharing it with me? :)

        Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche .·´¯`·->Rajesh<-·´¯`·. [Microsoft MVP - Visual C++]

        L 1 Reply Last reply
        0
        • R Rajesh R Subramanian

          How do you get formatted and colorised code like that? Is there a tool or something? Do you mind sharing it with me? :)

          Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche .·´¯`·->Rajesh<-·´¯`·. [Microsoft MVP - Visual C++]

          L Offline
          L Offline
          leppie
          wrote on last edited by
          #15

          Rajesh R Subramanian wrote:

          How do you get formatted and colorised code like that? Is there a tool or something? Do you mind sharing it with me?

          xacc.ide*, select text, right click, copy special, copy to HTML :) * see link below

          xacc.ide - now with TabsToSpaces support
          IronScheme - 1.0 alpha 4a out now (29 May 2008)

          R 1 Reply Last reply
          0
          • L leppie

            Rajesh R Subramanian wrote:

            How do you get formatted and colorised code like that? Is there a tool or something? Do you mind sharing it with me?

            xacc.ide*, select text, right click, copy special, copy to HTML :) * see link below

            xacc.ide - now with TabsToSpaces support
            IronScheme - 1.0 alpha 4a out now (29 May 2008)

            R Offline
            R Offline
            Rajesh R Subramanian
            wrote on last edited by
            #16

            It works with C++? Will I be able to specify a background color of my option? I know that I can modify the HTML, but I'm just asking. I'm downloading it at the moment. Thanks.

            Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche .·´¯`·->Rajesh<-·´¯`·. [Microsoft MVP - Visual C++]

            L 1 Reply Last reply
            0
            • R Rajesh R Subramanian

              It works with C++? Will I be able to specify a background color of my option? I know that I can modify the HTML, but I'm just asking. I'm downloading it at the moment. Thanks.

              Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche .·´¯`·->Rajesh<-·´¯`·. [Microsoft MVP - Visual C++]

              L Offline
              L Offline
              leppie
              wrote on last edited by
              #17

              Rajesh R Subramanian wrote:

              It works with C++?

              Not as nice as C#, but ok :)

              Rajesh R Subramanian wrote:

              Will I be able to specify a background color of my option? I know that I can modify the HTML, but I'm just asking.

              Nope, not IIRC, it just defaults to white, I cant remember if it picks up the color from the editor, or if that color can even be changed! Been very long since I wrote that :)

              xacc.ide - now with TabsToSpaces support
              IronScheme - 1.0 alpha 4a out now (29 May 2008)

              R 1 Reply Last reply
              0
              • L leppie

                Rajesh R Subramanian wrote:

                It works with C++?

                Not as nice as C#, but ok :)

                Rajesh R Subramanian wrote:

                Will I be able to specify a background color of my option? I know that I can modify the HTML, but I'm just asking.

                Nope, not IIRC, it just defaults to white, I cant remember if it picks up the color from the editor, or if that color can even be changed! Been very long since I wrote that :)

                xacc.ide - now with TabsToSpaces support
                IronScheme - 1.0 alpha 4a out now (29 May 2008)

                R Offline
                R Offline
                Rajesh R Subramanian
                wrote on last edited by
                #18

                I might give it a shot to add those features of my choice if time permits. I hardly work with C#. Thanks for the tool anyways.

                Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche .·´¯`·->Rajesh<-·´¯`·. [Microsoft MVP - Visual C++]

                1 Reply Last reply
                0
                • L leppie

                  Without compiling the following code, what will be the result, if run?

                  class Program
                  {
                  static void Main(string[] args)
                  {
                  object r = Foo(true);
                  Console.WriteLine(r.GetType());
                  Console.ReadLine();
                  }

                  static object Foo(bool e)
                  {
                  return e ? 0 : 0.0;
                  }
                  }

                  Now compile and run the code? Are you surprised? If so, try figure it out, if not, then kudos to you :)

                  xacc.ide - now with TabsToSpaces support
                  IronScheme - 1.0 alpha 4a out now (29 May 2008)

                  S Offline
                  S Offline
                  SomeGuyThatIsMe
                  wrote on last edited by
                  #19

                  i say double, but one of our new devs, thought it was a bool, then an object, then gave up and had me explain it. person has the same title as me too, funny how i never cared about that stuff until i got one. hopefully the other new guy will do better.

                  Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.

                  1 Reply Last reply
                  0
                  • G Gary Wheeler

                    Mustafa Ismail Mustafa wrote:

                    double, and I'd be surprised if it were anything else...

                    double, and I'd be surprised pissed off if it were anything else... (I'm in the process of learning C#)

                    Software Zen: delete this;

                    M Offline
                    M Offline
                    Mustafa Ismail Mustafa
                    wrote on last edited by
                    #20

                    Gary Wheeler wrote:

                    double, and I'd be surprised pissed off if it were anything else...

                    I stand corrected :)

                    Gary Wheeler wrote:

                    (I'm in the process of learning C#)

                    From what I remember, you're a C++er. Don't worry, you'll pick it up in no time flat, but you'll hate some stuff. const comes as a[n unpleasant] surprise and so do reflection issues. All in all, its a nice language :)

                    Don't forget to vote if the response was helpful


                    Sig history "dad" Ishmail-Samuel Mustafa "You're an idiot." John Simmons, THE Outlaw programmer "I realised that all of my best anecdotes started with "So there we were, pissed". Pete O'Hanlon Unix is a Four Letter Word, and Vi is a Two Letter Abbreviation

                    G 1 Reply Last reply
                    0
                    • L leppie

                      Without compiling the following code, what will be the result, if run?

                      class Program
                      {
                      static void Main(string[] args)
                      {
                      object r = Foo(true);
                      Console.WriteLine(r.GetType());
                      Console.ReadLine();
                      }

                      static object Foo(bool e)
                      {
                      return e ? 0 : 0.0;
                      }
                      }

                      Now compile and run the code? Are you surprised? If so, try figure it out, if not, then kudos to you :)

                      xacc.ide - now with TabsToSpaces support
                      IronScheme - 1.0 alpha 4a out now (29 May 2008)

                      P Offline
                      P Offline
                      piyush7419820
                      wrote on last edited by
                      #21

                      it will throw null exception.

                      1 Reply Last reply
                      0
                      • M Mustafa Ismail Mustafa

                        Gary Wheeler wrote:

                        double, and I'd be surprised pissed off if it were anything else...

                        I stand corrected :)

                        Gary Wheeler wrote:

                        (I'm in the process of learning C#)

                        From what I remember, you're a C++er. Don't worry, you'll pick it up in no time flat, but you'll hate some stuff. const comes as a[n unpleasant] surprise and so do reflection issues. All in all, its a nice language :)

                        Don't forget to vote if the response was helpful


                        Sig history "dad" Ishmail-Samuel Mustafa "You're an idiot." John Simmons, THE Outlaw programmer "I realised that all of my best anecdotes started with "So there we were, pissed". Pete O'Hanlon Unix is a Four Letter Word, and Vi is a Two Letter Abbreviation

                        G Offline
                        G Offline
                        Gary Wheeler
                        wrote on last edited by
                        #22

                        Mustafa Ismail Mustafa wrote:

                        From what I remember, you're a C++er.

                        Yes indeed. My portion of our next product (the UI) will be written in C#, since we have a requirement to use some WPF controls supplied by another group. Now, I've got a couple thousand pages of books to read to get started :).

                        Software Zen: delete this;

                        1 Reply Last reply
                        0
                        • L leppie

                          Without compiling the following code, what will be the result, if run?

                          class Program
                          {
                          static void Main(string[] args)
                          {
                          object r = Foo(true);
                          Console.WriteLine(r.GetType());
                          Console.ReadLine();
                          }

                          static object Foo(bool e)
                          {
                          return e ? 0 : 0.0;
                          }
                          }

                          Now compile and run the code? Are you surprised? If so, try figure it out, if not, then kudos to you :)

                          xacc.ide - now with TabsToSpaces support
                          IronScheme - 1.0 alpha 4a out now (29 May 2008)

                          P Offline
                          P Offline
                          PIEBALDconsult
                          wrote on last edited by
                          #23

                          Yeah, makes sense to me, the ternary operator isn't allowed to return different types, so the int is implicitly cast to double, just as expected. Of course I had to add System. to the Console methods to get it to compile...

                          B C 2 Replies Last reply
                          0
                          • P PIEBALDconsult

                            Yeah, makes sense to me, the ternary operator isn't allowed to return different types, so the int is implicitly cast to double, just as expected. Of course I had to add System. to the Console methods to get it to compile...

                            B Offline
                            B Offline
                            BoneSoft
                            wrote on last edited by
                            #24

                            Personally, I'm always using my System. ;P


                            Visit BoneSoft.com for code generation tools (XML & XSD -> C#, VB, etc...) and some free developer tools as well.

                            1 Reply Last reply
                            0
                            • J Jorgen Sigvardsson

                              Smart? Nah, I give experience credit for this. Also, if you think about it, it has to be this way. Numbers aren't that different from objects in OOP. I think this code makes it more apparent: (boolval ? new Car() : new AirPlane()).Fly();Since C# is statically typed, method selection can't be left to runtime binding. :)

                              A Offline
                              A Offline
                              Artiom Chilaru
                              wrote on last edited by
                              #25

                              In this case to be able to compile it you'll have to manually cast both objects to a base class, that has a Fly() methods :) While in the example of "? 0 : 0.0" the compiler does implicit casting

                              1 Reply Last reply
                              0
                              • L leppie

                                Without compiling the following code, what will be the result, if run?

                                class Program
                                {
                                static void Main(string[] args)
                                {
                                object r = Foo(true);
                                Console.WriteLine(r.GetType());
                                Console.ReadLine();
                                }

                                static object Foo(bool e)
                                {
                                return e ? 0 : 0.0;
                                }
                                }

                                Now compile and run the code? Are you surprised? If so, try figure it out, if not, then kudos to you :)

                                xacc.ide - now with TabsToSpaces support
                                IronScheme - 1.0 alpha 4a out now (29 May 2008)

                                C Offline
                                C Offline
                                cepi69
                                wrote on last edited by
                                #26

                                I would suggest you to read the "CLR via C#" book, by Jeffery Richter. ;P

                                1 Reply Last reply
                                0
                                • L leppie

                                  Without compiling the following code, what will be the result, if run?

                                  class Program
                                  {
                                  static void Main(string[] args)
                                  {
                                  object r = Foo(true);
                                  Console.WriteLine(r.GetType());
                                  Console.ReadLine();
                                  }

                                  static object Foo(bool e)
                                  {
                                  return e ? 0 : 0.0;
                                  }
                                  }

                                  Now compile and run the code? Are you surprised? If so, try figure it out, if not, then kudos to you :)

                                  xacc.ide - now with TabsToSpaces support
                                  IronScheme - 1.0 alpha 4a out now (29 May 2008)

                                  A Offline
                                  A Offline
                                  Alan Balkany
                                  wrote on last edited by
                                  #27

                                  D'ohh! My answer was: "System.Int32". (At least I'm being honest!) Although I haven't tested it, in retrospect it makes sense that the two conditional values should be the same type. Good quiz leppie!

                                  1 Reply Last reply
                                  0
                                  • P PIEBALDconsult

                                    Yeah, makes sense to me, the ternary operator isn't allowed to return different types, so the int is implicitly cast to double, just as expected. Of course I had to add System. to the Console methods to get it to compile...

                                    C Offline
                                    C Offline
                                    chaiguy1337
                                    wrote on last edited by
                                    #28

                                    Yeah this has caught me a few times, usually with a compile-time error. Kind of annoying.

                                    “Time and space can be a bitch.” –Gushie, Quantum Leap {o,o}.oO( Looking for a great RSS reader? Try FeedBeast! ) |)””’)            Built with home-grown CodeProject components! -”-”-

                                    1 Reply Last reply
                                    0
                                    • L leppie

                                      Without compiling the following code, what will be the result, if run?

                                      class Program
                                      {
                                      static void Main(string[] args)
                                      {
                                      object r = Foo(true);
                                      Console.WriteLine(r.GetType());
                                      Console.ReadLine();
                                      }

                                      static object Foo(bool e)
                                      {
                                      return e ? 0 : 0.0;
                                      }
                                      }

                                      Now compile and run the code? Are you surprised? If so, try figure it out, if not, then kudos to you :)

                                      xacc.ide - now with TabsToSpaces support
                                      IronScheme - 1.0 alpha 4a out now (29 May 2008)

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

                                      leppie wrote:

                                      compile and run the code

                                      My computer leapt off the table, ran in circles, peed on the carpet, then spent the rest of the day sulking behind the couch, presumably calling Dial-a-Byte on my cellphone over and over again.

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

                                      1 Reply Last reply
                                      0
                                      • L leppie

                                        Without compiling the following code, what will be the result, if run?

                                        class Program
                                        {
                                        static void Main(string[] args)
                                        {
                                        object r = Foo(true);
                                        Console.WriteLine(r.GetType());
                                        Console.ReadLine();
                                        }

                                        static object Foo(bool e)
                                        {
                                        return e ? 0 : 0.0;
                                        }
                                        }

                                        Now compile and run the code? Are you surprised? If so, try figure it out, if not, then kudos to you :)

                                        xacc.ide - now with TabsToSpaces support
                                        IronScheme - 1.0 alpha 4a out now (29 May 2008)

                                        W Offline
                                        W Offline
                                        W i N D
                                        wrote on last edited by
                                        #30

                                        The compiler's said test.cs(6,5): error CS0103: The name 'Console' does not exist in the current context test.cs(7,5): error CS0103: The name 'Console' does not exist in the current context because you aren't import System namespace or use full name like 'System.Console'

                                        1 Reply Last reply
                                        0
                                        • L leppie

                                          Without compiling the following code, what will be the result, if run?

                                          class Program
                                          {
                                          static void Main(string[] args)
                                          {
                                          object r = Foo(true);
                                          Console.WriteLine(r.GetType());
                                          Console.ReadLine();
                                          }

                                          static object Foo(bool e)
                                          {
                                          return e ? 0 : 0.0;
                                          }
                                          }

                                          Now compile and run the code? Are you surprised? If so, try figure it out, if not, then kudos to you :)

                                          xacc.ide - now with TabsToSpaces support
                                          IronScheme - 1.0 alpha 4a out now (29 May 2008)

                                          U Offline
                                          U Offline
                                          User 4366736
                                          wrote on last edited by
                                          #31

                                          The Foo method is expecting a reference type (object), but it is getting a value type, probably double. Now the question is, does C# convert the value type to a reference type (boxing)? The reference type would be converted to a Nullable (double?), I don't think so. I don't think it will return a compile error. So I believe it will result in a runtime error (don't know what it would be). I'll run it after this post and see. Tony

                                          U 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