Solved

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

Posted on 2011-09-06
2
220 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

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…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

809 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