Recently at a job interview during a technical test I had to answer a question:
What is the difference between a delegate and a multicast delegate?
Unfortunately I did not have the answer, I have used delegates plenty but I have never obviously used them enough to know this difference, and the dissapointing thing is that the answer was glaringly obvious.
A multicast delegate is multiple instances of the same delegate chained together using the + operator, Events in .NET make use of this to attach multiple event handlers to an event.
An example:
public delegate void SaySomething(string something); class Program { static void Main(string[] args) { // At first, something is just a delegate SaySomething something = new SaySomething((s) => Console.WriteLine(s)); // By adding together more instances of the SaySomething delegate. // we get a multicast delegate something += new SaySomething((s) => Console.WriteLine(s.ToUpper())); something += new SaySomething((s) => Console.WriteLine(s.ToLower())); something("Hello"); } }
The output would give:
HelloHELLOhello
It pains me to think I have now been at this for 6 years and there are still aspects to C# that I have not yet come across, yet I do not think of myself as a bad developer, I am sure there are plenty of things that I am aware of that the interviewer has no idea about, and it makes me wonder if the whole point is to see areas of where I could improve my knowledge, or the purpose is to scrutinise my knowledge in a way that an incorrect answer would make me out to be some kind of fraud.
I guess at least now if this question comes up again I will be able to answer it.
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.