TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
John
NA
1
0
Anonymous delegate with anonymous return value
Apr 15 2008 8:28 PM
I'm wondering if it's possible to have a method that accepts an anonymous delegate invoke on that delegate and have the delegate have a return value and then have that method return the value.
The requirements are:
1. The anonymous delegate must be able to incapsulate parameters, like the Action<> object.
2. The anonymous delegate must be able to have a return type like: string returnValue = actionMethod.Invoke();
Example of the concept:
public void CallRetrieveDataFunction()
{
IRandomInterface classMain = new ClassMain();
Action <IRandomInterface> invokeMethod = delegate(IRandomInterface executeReference) { executeReference.GetProductByID(productID); };
object response = RetrieveData(invokeMethod, classMain);
}
public object RetrieveData(Action<T> methodToExecute, U referenceOfObjectImplementingInterface)
{
object returnValue;
returnValue = methodToExecute.Invoke(U);
return returnValue;
}
Anybody have any ideas?
Reply
Answers (
2
)
Alert message in C#
Tabbed Pages