<< Friday Java Quiz: Incompatible Language Changes | Home | JavaFX FAQ 1: Why The UnsupportedClassVersionError >>

Friday C# Quiz: Know Your Closures

Although I've vowed not to post about closures anymore, I can't help but post one more quiz. I know Friday is mostly over for many of my readers, but there are still a few time zones left.

Without downloading Microsoft Visual C# 2008 Express Edition and compiling the following C# source file, answer the following question:

Q: Will the following program

public delegate int IntToInt(int i);

public class Foo {
  public static IntToInt fib =
    n => n == 0 ? 0 :
         n == 1 ? 1 :
         fib(n - 1) + fib(n - 2);

  public static void Main() {
    System.Console.WriteLine(fib(6));
  }
}

compile? Run? If so, what will it print out?



Re: Friday C# Quiz: Know Your Closures

I cheated -- but nice!!! (I won't say what it prints as to give others the chance :) PS it was because my c# knowledge is weak. If you're running linux or *bsd you can run this using Mono =)

Add a comment Send a TrackBack