delegate as parameter

In this chapter you will learn:

  1. Use delegate as the function parameter

Use delegate as the function parameter

using System;//from  ja v a2 s.c  o  m
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.InteropServices;

delegate void FooBar();

public class MainClass
{
    static void Invoke3Times(FooBar d)
    {
        d(); d(); d();
    }

   public static void Main(){
        int i = 0;
        Invoke3Times(delegate { i++; });
        Console.WriteLine(i);

   }

}

The code above generates the following result.

Next chapter...

What you will learn in the next chapter:

  1. Event and delegate
  2. Example for creating event
Home » C# Tutorial » delegate, lambda, event
delegate
Multicast delegate
delegate variables
delegate parameters
Generic delegate
delegate return
Func and Action
delegate new
chained delegate
Anonymous delegate
delegate array
Return a delegate
delegate as parameter
Event
event multicast
static event
EventHandler
Event pattern
lambda
lambda syntax
Func, Action and lambda
lambda with outer function
lambda iteration variables