Which lines will cause compilation errors?
 
public class Foo 
{ 
   public Action A; 
   public Action B { get; private set; }
   public event Action C; 
}

 public static class Program 
{
    public static void Main() 
    {  
        Foo foo = new Foo(); 
        foo.A += () => { }; // 1 
        foo.A();             // 2 
        foo.B += () => { }; // 3 
        foo.B();             // 4
        foo.C += () => { }; // 5 
        foo.C();             // 6 
    } 
}
 
Explanation
A is a delegate. Methods can be added to it and it can be called; B is a delegate available through the write protected property. Delegate B can only be called from another class, not modified; C is an event. Methods can be added to it. Event can be called only from a class it is declared in. http://msdn.microsoft.com/ru-ru/library/8627sbea(VS.90).aspx

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Cosmo
Sign Up Now
or Subscribe for future quizzes