C# teasers

  • Thread starter Thread starter Ludwig
  • Start date Start date
L

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!
 
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!
 
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
 
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 :)
 
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 ;)
 
Ludwig said:
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!
 
Ludwig said:
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
 
Brian Gideon said:
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 :)
 
Indeed. Unless they were claiming to know absolutely everything about
C#, in which case anything is fair game.


Absolutely - I've been meaning to do something like it for a while.
This thread was a catalyst :)

Here's another nice one:

Console.WriteLine(1 + 2 + "3");
Console.WriteLine("1" + 2 + 3);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top