two delegates and anonymous methods

image_pdfimage_print
   
  

using System;


public delegate void ADelegate(int param);
public delegate int BDelegate(int param1, int param2);

public class Starter {
    public static void Main() {
        ADelegate del = delegate(int param) {
            param = 5;
        };
    }

    public int MethodA() {
        BDelegate del = delegate(int param1, int param2) {
            return 0;
        };
        return 0;
    }
}

   
     


Anonymous methods can refer to local variables of the containing function and class members within the scope of the method definition

image_pdfimage_print
   
  

using System;

public delegate void DelegateClass(out int arg);

public class Starter {

    public static void Main() {

        DelegateClass del = MethodA();
        int var;
        del(out var);

        Console.WriteLine(var);
    }

    public static DelegateClass MethodA() {
        int local = 0;
        return delegate(out int arg) {
            arg = ++local;
        };
    }
}

   
     


The continue statement

image_pdfimage_print

/*
Mastering Visual C# .NET
by Jason Price, Mike Gunderloy

Publisher: Sybex;
ISBN: 0782129110
*/

/*
Example4_14.cs illustrates the use of
the continue statement
*/

public class Example4_14
{

public static void Main()
{

int total = 0;

for (int counter = 1; counter <= 10; counter++) { if (counter == 6) { System.Console.WriteLine("continue from loop start"); continue; } System.Console.WriteLine("counter = " + counter); total += counter; } System.Console.WriteLine("total = " + total); } } [/csharp]