Solved

how to pass parameter to Action a = () =>

Posted on 2011-09-06
2
219 Views
Last Modified: 2012-06-27
I want to stay away from multithread racing condition which is correct usage.

obj
Action a = () =>
                        {
                            ... use obj parameter here
                        };

or

Action<class> a =
                    (obj) =>
                    {
                        ... use obj here ....
                    };

a is use later in the code.
0
Comment
Question by:JSW21
2 Comments
 
LVL 7

Accepted Solution

by:
Gewgala earned 500 total points
ID: 36490778
This is how I have done it:

object myObj = "example";

Action<object> objectAction = c => ObjectActionMethod(c);

Open in new window


Then use action like delegate:

objectAction(myObj);

Open in new window



and the ObjectActionMethod definition:

public void ObjectActionMethod(object param)
{
     Console.WriteLine(param.ToString());  // writes "example"
}

Open in new window

0
 

Author Closing Comment

by:JSW21
ID: 36503743
Thanks
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
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…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

776 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