Ian (Fluxtah) Warwick's blog RSS 2.0
# Thursday, February 12, 2009

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:

Hello
HELLO
hello

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.

Thursday, February 12, 2009 6:20:00 AM (GMT Standard Time, UTC+00:00)  #    Comments [3] -
C#
Archive
<February 2009>
SunMonTueWedThuFriSat
25262728293031
1234567
891011121314
15161718192021
22232425262728
1234567
Blogroll
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2012
Ian Warwick
Sign In
Statistics
Total Posts: 33
This Year: 0
This Month: 0
This Week: 0
Comments: 4
Themes
Pick a theme:
All Content © 2012, Ian Warwick
DasBlog theme 'Business' created by Christoph De Baene (delarou)