Solved

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

Posted on 2011-09-06
2
216 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
Comment Utility
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
Comment Utility
Thanks
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now