CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2006
    Posts
    134

    What does "()=>" mean?

    Greetings!

    A source code file for a .Net 3.5 application contains the following code in the beginning of an array definition:

    A C# source code file I am hoping to use in a project of my own has an array definition that begins with the following code:

    stf.ParseBlock(new STFReader.TokenProcessor[] {
    new STFReader.TokenProcessor("eventtypelocation", ()=>{ stf.SkipBlock(); }),

    What does the "()=>" mean? I've never seen that construct before.

    Thanks very much!

    RobR

  2. #2
    Join Date
    Aug 2006
    Posts
    134

    Re: What does "()=>" mean?

    I found it. => means "goes to" in a lambda expression. I am embarrassed that I didn't look in the C# help file before I posted here. My apologies for wasting bandwidth.

  3. #3
    Join Date
    Aug 2008
    Posts
    902

    Re: What does "()=>" mean?

    It's C#'s version of lambda functions, also called closures or anonymous functions.

    Code:
    delegate int myDelegate(int number);
    delegate int myDelegate2(int number1, int number2);
    
    myDelegate del = i => i + 1;
    myDelegate2 del2 = (i, j) => i + j;
    
    int a = del(42); // returns 43
    int b = del2(42, 5); // returns 47
    
    List<string> myStrings = new List<string>();
    // Add Strings
    myStrings.ForEach( i => Console.WriteLine(i) );

  4. #4
    Join Date
    Sep 2010
    Posts
    7

    Re: What does "()=>" mean?

    see this link to understand lamda expressions .. it's a part from linq to working with data in fast and easy way

  5. #5
    Join Date
    Jun 2008
    Posts
    2,477

    Re: What does "()=>" mean?

    Quote Originally Posted by ClassCoder View Post
    see this link to understand lamda expressions .. it's a part from linq to working with data in fast and easy way
    Lambda expressions existed in .NET before LINQ did, though they are used heavily when using LINQ.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured