?
Solved

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

Posted on 2011-09-06
2
Medium Priority
?
226 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 2000 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

Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Screencast - Getting to Know the Pipeline
Suggested Courses
Course of the Month14 days, 14 hours left to enroll

839 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