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

x
?
Solved

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

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

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