C# -- How to handle duplicate multicastdelegate?
<p>Since we register the callback function <strong>PrintOne</strong> twice, the following code will print the message "PrintOne" twice. Here are questions,</p>

<p>Question 1> Why  by default the operator+=(i.e. Combine) doesn't check duplicate method handler?</p>

<p>Question 2> How to avoid this duplicated call in method RegisterCall? I try to find some method in MulticastDelegate/Delegate that can tell me there is already one in the calling list. But I didn't find it.
<a href="http://msdn.microsoft.com/en-us/library/system.multicastdelegate.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/system.multicastdelegate.aspx</a></p>

<p>Thank you</p>

<pre><code>using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace app3
{
    class Car
    {
        public delegate void PrintMethod(string msg);

        public string Name { get; set; }

        private PrintMethod printMethods;

        public Car() { }
        public Car(string name) { Name = name; }

        public void PrintCar()
        {
            if (printMethods != null)
            {
                printMethods(this.ToString());
            }
            else
            {
                Console.WriteLine("No Method will be called");
            }
        }
        public override string ToString()
        {
            return string.Format("Car Name is {0}: ", Name);
        }

        public static void PrintOne(string msg)
        {
            Console.WriteLine("PrintOne");
        }

        public static void PrintTwo(string msg)
        {
            Console.WriteLine("PrintTwo");
        }

        public void RegisterCall(PrintMethod methodToCall)
        {
            printMethods += methodToCall;
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Car mycar = new Car { Name = "BMW" };
            mycar.RegisterCall(new Car.PrintMethod(Car.PrintOne)); // **will print for the first time**
            mycar.RegisterCall(new Car.PrintMethod(Car.PrintOne)); // **will print for the second time**
            mycar.PrintCar();

            Console.ReadLine();
        }
    }
}
</code></pre>
