C# teasers

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ludwig

    C# teasers

    Hi,
    I'm looking for C# brain teasers (or VB.NET): a little piece of code
    that does something special, or where a little error is. Does anyone
    has some of these, or links to sites?
    Thanks!
  • Jon Skeet [C# MVP]

    #2
    Re: C# teasers

    On Nov 27, 1:14 pm, Ludwig <lstuyc...@gmai l.comwrote:
    I'm looking for C# brain teasers (or VB.NET): a little piece of code
    that does something special, or where a little error is. Does anyone
    has some of these, or links to sites?
    Are you after "this doesn't do what you think it does" type things (eg
    overloading special cases, or captured variables) or "you should be
    able to get this really" questions?

    Jon

    Comment

    • Michael Nemtsev [MVP]

      #3
      Re: C# teasers

      Hello Ludwig,

      Use the MS certification preparation matherials for this.
      They are a good source for such kind of teasers

      ---
      WBR,
      Michael Nemtsev [.NET/C# MVP] :: blog: http://spaces.live.com/laflour

      "The greatest danger for most of us is not that our aim is too high and we
      miss it, but that it is too low and we reach it" (c) Michelangelo


      LHi,
      LI'm looking for C# brain teasers (or VB.NET): a little piece of code
      Lthat does something special, or where a little error is. Does anyone
      Lhas some of these, or links to sites?
      LThanks!


      Comment

      • Ludwig

        #4
        Re: C# teasers

        On 27 nov, 15:01, "Jon Skeet [C# MVP]" <sk...@pobox.co mwrote:
        On Nov 27, 1:14 pm, Ludwig <lstuyc...@gmai l.comwrote:
        >
        I'm looking for C# brain teasers (or VB.NET): a little piece of code
        that does something special, or where a little error is. Does anyone
        has some of these, or links to sites?
        >
        Are you after "this doesn't do what you think it does" type things (eg
        overloading special cases, or captured variables) or "you should be
        able to get this really" questions?
        >
        Jon
        Both :)

        Comment

        • Jon Skeet [C# MVP]

          #5
          Re: C# teasers

          On Nov 27, 2:33 pm, Ludwig <lstuyc...@gmai l.comwrote:

          <snip>
          Both :)
          Okay. I've a few ideas - I'll post some tonight.

          Jon

          Comment

          • Ludwig

            #6
            Re: C# teasers

            On 27 nov, 15:41, "Jon Skeet [C# MVP]" <sk...@pobox.co mwrote:
            On Nov 27, 2:33 pm, Ludwig <lstuyc...@gmai l.comwrote:
            >
            <snip>
            >
            Both :)
            >
            Okay. I've a few ideas - I'll post some tonight.
            >
            Jon
            Thank you! Meanwhile I'm looking into the certification books - I've
            to take the exams anyway, so it's a good waste of time ;)

            Comment

            • =?Utf-8?B?b2xkbWFuNjk=?=

              #7
              RE: C# teasers



              "Ludwig" wrote:
              Hi,
              I'm looking for C# brain teasers (or VB.NET): a little piece of code
              that does something special, or where a little error is. Does anyone
              has some of these, or links to sites?
              Thanks!
              >

              Comment

              • =?Utf-8?B?b2xkbWFuNjk=?=

                #8
                RE: C# teasers

                I have a program that finds prime numbers, if you are interested.

                "Ludwig" wrote:
                Hi,
                I'm looking for C# brain teasers (or VB.NET): a little piece of code
                that does something special, or where a little error is. Does anyone
                has some of these, or links to sites?
                Thanks!
                >

                Comment

                • Chris Mullins [MVP - C#]

                  #9
                  Re: C# teasers

                  There's one here that threw me for a loop late one night:



                  Other fun ones include some of Joe Duffy's (and Jon Skeet's) examples of
                  broken double-check locks.

                  --
                  Chris Mullins

                  "Ludwig" <lstuyck73@gmai l.comwrote in message
                  news:11bc359a-1e08-407c-b2d0-fd4a425a6af7@s1 2g2000prg.googl egroups.com...
                  Hi,
                  I'm looking for C# brain teasers (or VB.NET): a little piece of code
                  that does something special, or where a little error is. Does anyone
                  has some of these, or links to sites?
                  Thanks!

                  Comment

                  • Hilton

                    #10
                    Re: C# teasers

                    x = x & (x-1)


                    "Ludwig" <lstuyck73@gmai l.comwrote in message
                    news:11bc359a-1e08-407c-b2d0-fd4a425a6af7@s1 2g2000prg.googl egroups.com...
                    Hi,
                    I'm looking for C# brain teasers (or VB.NET): a little piece of code
                    that does something special, or where a little error is. Does anyone
                    has some of these, or links to sites?
                    Thanks!

                    Comment

                    • Alun Harford

                      #11
                      Re: C# teasers

                      Ludwig wrote:
                      Hi,
                      I'm looking for C# brain teasers (or VB.NET): a little piece of code
                      that does something special, or where a little error is. Does anyone
                      has some of these, or links to sites?
                      Special? How about this:

                      Why does this compile:

                      public class Program{
                      public static void Main(string[] args){
                      TypedReference typedReference = new TypedReference( );
                      }
                      }

                      and this not compile:

                      public class Program{
                      public static void Main(string[] args){
                      object typedReference = new TypedReference( );
                      }
                      }

                      Alun Harford

                      Comment

                      • Jon Skeet [C# MVP]

                        #12
                        Re: C# teasers

                        Ludwig <lstuyck73@gmai l.comwrote:

                        <snip>
                        Thank you! Meanwhile I'm looking into the certification books - I've
                        to take the exams anyway, so it's a good waste of time ;)
                        Here are some to be going on with. I'll add to the list as I remember
                        them...

                        Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.


                        --
                        Jon Skeet - <skeet@pobox.co m>
                        http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
                        World class .NET training in the UK: http://iterativetraining.co.uk

                        Comment

                        • Brian Gideon

                          #13
                          Re: C# teasers

                          On Nov 27, 2:46 pm, Jon Skeet [C# MVP] <sk...@pobox.co mwrote:
                          Here are some to be going on with. I'll add to the list as I remember
                          them...
                          >
                          Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

                          >
                          --

                          I love #2. I've seen your blog about beforefieldinit before. It
                          would be plain wrong to ask somebody that question in an interview :)

                          By the way, you should keep adding to that page periodically or as you
                          run across a good one.

                          Comment

                          • Brian Gideon

                            #14
                            Re: C# teasers

                            On Nov 27, 7:14 am, Ludwig <lstuyc...@gmai l.comwrote:
                            Hi,
                            I'm looking for C# brain teasers (or VB.NET): a little piece of code
                            that does something special, or where a little error is. Does anyone
                            has some of these, or links to sites?
                            Thanks!
                            This one piqued my interest some time back.


                            Comment

                            • Jon Skeet [C# MVP]

                              #15
                              Re: C# teasers

                              Brian Gideon <briangideon@ya hoo.comwrote:
                              I love #2. I've seen your blog about beforefieldinit before. It
                              would be plain wrong to ask somebody that question in an interview :)
                              Indeed. Unless they were claiming to know absolutely everything about
                              C#, in which case anything is fair game.
                              By the way, you should keep adding to that page periodically or as you
                              run across a good one.
                              Absolutely - I've been meaning to do something like it for a while.
                              This thread was a catalyst :)

                              --
                              Jon Skeet - <skeet@pobox.co m>
                              http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
                              World class .NET training in the UK: http://iterativetraining.co.uk

                              Comment

                              Working...