1 Replies - 298 Views - Last Post: 06 October 2012 - 10:50 PM Rate Topic: -----

#1 HopelessDev  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 136
  • Joined: 10-August 12

Delegates question

Posted 06 October 2012 - 10:07 PM

Why are delegates called using the Class names and not the Class reference variable? For example this delegate from Car class

public delegate void CarEngineHandler(string msg);

static void Main(string[] args) 
{
    Car c1 = new Car();
    //error
    c1.Explode += new c1.CarEngineHandler(CallMyName);

    //okay
    c1.Explode += new Car.CarEngineHandler(CallMyName);
}


This post has been edited by HopelessDev: 06 October 2012 - 10:08 PM

Is This A Good Question/Topic? 0
  • +

Replies To: Delegates question

#2 Momerath  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1012
  • View blog
  • Posts: 2,444
  • Joined: 04-October 09

Re: Delegates question

Posted 06 October 2012 - 10:50 PM

Because it is a type, not a variable.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1