noimage

TechQuiz Question 7: Calling derived methods..

What is the result of the following code? using System; class Base {     public virtual void Foo(int x) { Console.WriteLine(“Base.Foo(int)”); } } class Derived : Base {     public override void Foo(int x)  { Console.WriteLine(“Derived.Foo(int)”); }     public void Foo(object o)  { Console.WriteLine(“Derived.Foo(object)”); } } class Test {     static void Main()     {         Derived d = new...

noimage

TechQuiz Question 6: Getting some closure…

What will be the output of the following code? using System; using System.Collections.Generic; class Test {     delegate void Printer();         static void Main()     {         List<Printer> printers = new List<Printer>();         for (int i = 0; i < 10; i++)         {             printers.Add(delegate { Console.WriteLine(i); });         }                 foreach (Printer printer in printers)        ...

noimage

TechQuiz Question 3: Nullable boxing

Why does Foo<int?> throw an exception? 1: static void Foo<T>() where T : new() 2: { 3: T t = new T(); 4: Console.WriteLine(“ToString: ” + t.ToString()); 5: Console.WriteLine(“GetHashCode: ” + t.GetHashCode()); 6: Console.WriteLine(“Equals: ” + t.Equals(t)); 7: Console.WriteLine(“GetType: ” + t.GetType()); 8: } 9:   10: public void Main() 11: { 12: Foo<int>(); 13: Foo<int?>(); // Exception thrown 14:...