Question 1: Does the following program compile? If not, why? If so, or if compilation errors are corrected, what is its output?
#define classnamespace Test{#if class /* should compile? */ class @class { public int @int(short @int) { return (int)@int + 2; } public int \u0069nt(byte o) { return 4; } }#endif class Program { static void Main() { @class @int = new @class(); System.Console.WriteLine(@int.@int(5)); } }}
Question 2: What is the output of the following program?
class A{ int i; public A(int i) { this.i = i; } public static explicit operator A(int i) { return new A(i); } public override string ToString() { return i.ToString(); }}class Program{ static void Main() { int A = 4; System.Console.WriteLine((A)-5); System.Console.WriteLine((A)(-5)); }}
Question 3: Does this program compile? If so, what is its output?
struct Foo{ static readonly Foo F = new Foo(5); public int I; public Foo(int i) { I = i; this = F; }}class Program{ static void Main() { Foo f = new Foo(2); System.Console.WriteLine(f.I); }}
Question 4: What is the output of the following program?
class Program{ class A { } class B { } static void Main() { int A = 10; int B = 20; int G = 15; F(G < A, B > (-7)); F(G < A, B > -7); } static void F(int i) { System.Console.WriteLine(i); } static void F(bool b1, bool b2) { System.Console.WriteLine("{0} {1}", b1, b2); } static int G(int v) { return v; }}
Question 5: Is the following defined behavior? If so, what is its output?
class Test{ static int a = b + 1; static int b = a + 1; static void Main() { System.Console.WriteLine("a = {0}, b = {1}", a, b); }}
Have at it!
A1: Correct, incorrect, correct
A2: Incorrect
A3: Correct, incorrect (Correct reasoning, tripped up on the details)
A4: Correct
A5: 99% certain I'm correct, Correct
If we're only counting entirely correct answers, that's only a 40% grade. FFFFFFFF...