public class Class1
{
public int Method1(string input)
{
//... do something
return 0;
}
public int Method2(string input)
{
//... do something different
return 1;
}
public bool RunTheMethod(Func<string, int> myMethodName)
{
//... do stuff
int i = myMethodName("My String");
//... do more stuff
return true;
}
public bool Test()
{
return RunTheMethod(Method1);
}
}
Member
1 Points
18 Posts
Method with Func as parameter
Oct 26, 2014 12:33 PM|iAndy|LINK
How do i write a method for this test?
I was thinking a extension method that takes a func as parameter?
Something like:
public static IEnumerable Keep(this Func<int, IEnumerable>) but i need some help?
Thanks.
lambda
All-Star
19919 Points
2016 Posts
Re: Method with Func as parameter
Oct 27, 2014 11:07 PM|Eileen ni - MSFT|LINK
Hi iAndy,
Thanks for your post.
Here is an example that should work:
More information:
Method using Func<T,TResult> as parameters
Func<T, TResult> Delegate
How to Pass Method or Function as Parameter in C# ?
Hope this can be helpful.
Best Regards,
Eileen
lambda