Monday, June 29, 2009

C# Puzzle No.18 (beginner)

Your goal is to convert an array into a string.

int[] TheArray = new int[] { 1, 2, 3, 6, 7, 8 };
 
string TheArrayString = TheArray.????;
 
Console.WriteLine( TheArrayString );

Replace the "????" placeholder with a valid C# expression so that the output of the above snippet on the console is:



1, 2, 3, 6, 7, 8

Thursday, June 4, 2009

C# Puzzle No.17 (beginner)

Consider following code:

   1: using System;
   2:  
   3: class Foo
   4: {
   5:     private Foo() { }
   6: }
   7:  
   8: class Program : Foo
   9: {
  10:     static void Main( string[] args )
  11:     {
  12:     }
  13: }

The compiler says that



Foo() is inaccessible due to its protection level

But wait a sec, there's no need to complain since there's no attempt to create an instance of Foo!


In fact, the keyword "new" is never used in the code. It shouldn't then matter whether Foo is or is not accessible.


Your goal is to explain the compiler's complaint.