An anonymous method that takes an argument
using System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
namespace
DemonsAnoynmous
{
// Notice that
CountIt now has a parameter.
delegate void CountIt(int end);
class Program
{
static void Main(string[] args)
{
// Here,
the ending value for the count
// is
passed to the anonymous method.
CountIt
count = delegate(int
end)
{
for
(int i = 0; i <= end; i++)
Console.WriteLine(i);
};
count(3);
Console.WriteLine();
count(5);
Console.ReadKey();
}
}
}
No comments:
Post a Comment