Home All Groups Group Topic Archive Search About
Author
27 Nov 2007 1:14 PM
Ludwig
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!

Author
27 Nov 2007 1:55 PM
Michael Nemtsev [MVP]
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


L> Hi,
L> I'm looking for C# brain teasers (or VB.NET): a little piece of code
L> that does something special, or where a little error is. Does anyone
L> has some of these, or links to sites?
L> Thanks!
Author
27 Nov 2007 2:01 PM
Jon Skeet [C# MVP]
On Nov 27, 1:14 pm, Ludwig <lstuyc***@gmail.com> wrote:
> 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
Author
27 Nov 2007 2:33 PM
Ludwig
On 27 nov, 15:01, "Jon Skeet [C# MVP]" <sk***@pobox.com> wrote:
> On Nov 27, 1:14 pm, Ludwig <lstuyc***@gmail.com> wrote:
>
> > 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 :)
Author
27 Nov 2007 2:41 PM
Jon Skeet [C# MVP]
On Nov 27, 2:33 pm, Ludwig <lstuyc***@gmail.com> wrote:

<snip>

> Both :)

Okay. I've a few ideas - I'll post some tonight.

Jon
Author
27 Nov 2007 2:49 PM
Ludwig
On 27 nov, 15:41, "Jon Skeet [C# MVP]" <sk***@pobox.com> wrote:
> On Nov 27, 2:33 pm, Ludwig <lstuyc***@gmail.com> wrote:
>
> <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 ;)
Author
27 Nov 2007 8:46 PM
Jon Skeet [C# MVP]
Ludwig <lstuyc***@gmail.com> wrote:

<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...

http://pobox.com/~skeet/csharp/teasers.html

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
Author
27 Nov 2007 9:16 PM
Brian Gideon
On Nov 27, 2:46 pm, Jon Skeet [C# MVP] <sk***@pobox.com> wrote:
> Here are some to be going on with. I'll add to the list as I remember
> them...
>
> http://pobox.com/~skeet/csharp/teasers.html
>
> --


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.
Author
27 Nov 2007 9:27 PM
Jon Skeet [C# MVP]
Brian Gideon <briangid***@yahoo.com> wrote:
> 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 - <sk***@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
Author
28 Nov 2007 6:34 PM
Ludwig
On 27 nov, 22:27, Jon Skeet [C# MVP] <sk***@pobox.com> wrote:
Show quote
> Brian Gideon <briangid***@yahoo.com> wrote:
> > 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 - <sk***@pobox.comhttp://www.pobox.com/~skeet  Blog:http://www.msmvps.com/jon.skeet
> World class .NET training in the UK:http://iterativetraining.co.uk

Here's another nice one:

Console.WriteLine(1 + 2 + "3");
Console.WriteLine("1" + 2 + 3);
Author
28 Nov 2007 6:24 AM
Ludwig
On 27 nov, 21:46, Jon Skeet [C# MVP] <sk***@pobox.com> wrote:
Show quote
> Ludwig <lstuyc***@gmail.com> wrote:
>
> <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...
>
> http://pobox.com/~skeet/csharp/teasers.html
>
> --
> Jon Skeet - <sk***@pobox.comhttp://www.pobox.com/~skeet  Blog:http://www.msmvps.com/jon.skeet
> World class .NET training in the UK:http://iterativetraining.co.uk

Perfect, I've bookmarked your site and will have a look!! Thanks!
Author
27 Nov 2007 3:30 PM
oldman69
Show quote
"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!
>
Author
27 Nov 2007 3:32 PM
oldman69
I have a program that finds prime numbers, if you are interested.

Show quote
"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!
>
Author
27 Nov 2007 6:21 PM
Chris Mullins [MVP - C#]
There's one here that threw me for a loop late one night:

http://groups.google.com/group/microsoft.public.dotnet.framework/browse_frm/thread/9d5ad8caf1bf1c20/344fc9ba3b43ae3b

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

--
Chris Mullins

Show quote
"Ludwig" <lstuyc***@gmail.com> wrote in message
news:11bc359a-1e08-407c-b2d0-fd4a425a6af7@s12g2000prg.googlegroups.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!
Author
27 Nov 2007 6:24 PM
Hilton
x = x & (x-1)


Show quote
"Ludwig" <lstuyc***@gmail.com> wrote in message
news:11bc359a-1e08-407c-b2d0-fd4a425a6af7@s12g2000prg.googlegroups.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!
Author
27 Nov 2007 7:39 PM
Alun Harford
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
Author
27 Nov 2007 9:23 PM
Brian Gideon
On Nov 27, 7:14 am, Ludwig <lstuyc***@gmail.com> 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!

This one piqued my interest some time back.

http://groups.google.com/group/microsoft.public.dotnet.languages.csharp/browse_frm/thread/686e2d628962b8c8/720965d37f201ddb?lnk=st&q=specification#720965d37f201ddb

AddThis Social Bookmark Button