Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

C#: what is the operator => doing?

Posted on 2010-08-14
4
Medium Priority
?
358 Views
Last Modified: 2013-12-17
Hi Experts:

I saw a section of C# code:
***************************************************************************************  
          System.Threading.ThreadPool.QueueUserWorkItem((state) =>
            {
                System.Threading.Thread.Sleep(3 * 1000);
                Dispatcher.BeginInvoke(() => BusyNote.IsBusy = false); }
            );
****************************************************************************************

Can anybody tell me what is the operator "=>" doing? and what is this section of code doing?
I know it is related to threading , but I don't understand the syntax involving "=>"

This section of code is from a SilverLight 4 application.


Thank you.
0
Comment
Question by:huangs3
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 30

Accepted Solution

by:
Reza Rad earned 1600 total points
ID: 33439384
=> is LAMBDA operator,
there are lots of useful things you can do with Lambda operator, take a look at these links:
http://msdn.microsoft.com/en-us/library/bb397687.aspx
http://www.switchonthecode.com/tutorials/csharp-tutorial-the-lambda-operator

0
 
LVL 2

Assisted Solution

by:Algol36
Algol36 earned 200 total points
ID: 33439583
Over and above this code use anonimous method equivalent to the following:
...
Dispatcher.BeginInvoke(MyMethod}
...
void MyMethod()
{
  BusyNote.IsBusy = false;
}
0
 
LVL 1

Assisted Solution

by:funazonki
funazonki earned 200 total points
ID: 33440377
It might help to look at a simpler example - the lambda operator allows you to define anonymous functions that can be passed to other functions as parameters. The case you use above is a parameterless function. you can also define functions that take parameters. For example the following code calls the Count function that takes a boolean function as a parameter and returns the number of elements in the list for which the boolean is true.

                List<string> data = new List<string> { "one", "two", "three" };
                Console.WriteLine(data.Count(t=>t.Contains("o")));

The Console.WriteLine will write "2" to the console.
0
 

Author Closing Comment

by:huangs3
ID: 33442343
reza_rad has the earliest and the most important answer while Algol36 and funazonik provided the helpful examples.
0

Featured Post

What’s Wrong with Your Cloud Strategy ?

Even as many CIOs are embracing a cloud-first strategy, the reality is that moving to the cloud is a lengthy process and the end-state is likely to be a blend of multiple clouds—public and private. Learn why multicloud solutions matter in this webinar by Nimble Storage.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question