Saturday, June 09, 2007

C# Quiz #1: overloads, strings, nullable types

*This is also a test of the latest Windows Live Writer

given this class definition:

public class Foo {
public void Bar(string x) {
Console.WriteLine("string x was called");
public void Bar(int? x) {
Console.WriteLine("int? x was called");

what will be output to the console with the following code:

Foo f = new Foo();
try {
catch {
Console.WriteLine("no method was called");

*update: I messed up the code while trying to upload another post, I recovered the original post from my RSS feed

1 comment:

Steven said...

I just couldn't believe this would compile, so I had to check. Luckily my first hunch was right. :-)