c# 4.0 - Func delegate passed over a function -
i have following code:
private void example(func<string,int> mydelegate) { int length = mydelegate(receivedstring).; //how access received string?? }
when execute method : example(x=>"hello".length); how can access string "hello" inside method example?
thanks.
regards.
jose.
that not how should processing delegate. takes input parameter , example
needs know details input parameter in order execute delegate. here example
"acts" interface external code , external code must provide own implementation. if example
needs execute delegate needs provide required string parameter. imho, example
needs provide second parameter in signature below...
private void example(string s, func<string,int> mydelegate) { int length = mydelegate(s); }
then external code can provide own implementation , parameter...
example("hello", x => { return x.length; });
what trying not possible in c#
, delegate needs explicit context run, context string input parameter.
hope makes sense
Comments
Post a Comment