Monday, 9 August 2010

C# Delegate List

[TestFixture]
public class TestDelegate
{
    public delegate void SampleDelegate();
    List<SampleDelegate> SampleDelegates = new List<SampleDelegate>();
    [Test]
    public void Test()
    {
        SampleDelegates.Add(Sample1);
        SampleDelegates.Add(Sample2);
        foreach (SampleDelegate sampleDelegate in SampleDelegates)
        {
            sampleDelegate();
        }
    }
    public void Sample1()
    {
        Console.WriteLine("Sample 1");
    }
    public void Sample2()
    {
        Console.WriteLine("Sample 2");
    }
}

No comments:

Post a Comment