You can't do Func<out char, int> ?
Is there a correct syntax for representing a function that takes a reference as a parameter, or is this not allowed?
-
-
The first parameter of Func<TResult, TArg1> is the return type of the function, so no, you can't do that.
Func<char, int> corresponds to a function with signaturechar foo(int parameter) {} -
evildictator,evildictaitor said:The first parameter of Func<TResult, TArg1> is the return type of the function, so no, you can't do that.Func<char, int> corresponds to a function with signaturechar foo(int parameter) {}
The syntax shown in Visual Studio is Func<T, TResult> where T is a parameter.
Either way, it won't let me pass in a type parameter by reference.
-
You have the parameter order correct, but you still can't do what you want. The only thing a generic parameter can express is a type. The The parameter direction is defined by the Func<> delegate itself, and you can't change it. Depending on what you're trying to do, you can define your own delegate apart from Func<>. Something like this, perhaps:brian.shapiro said:
evildictator,evildictaitor said:*snip*
The syntax shown in Visual Studio is Func<T, TResult> where T is a parameter.
Either way, it won't let me pass in a type parameter by reference.public delegate int MyDelegate(out char value);
Actually, I'm not 100% sure the above is valid. An "out" parameter on a delegate may not be valid. -
That works.dpratt71 said:
You have the parameter order correct, but you still can't do what you want. The only thing a generic parameter can express is a type. The The parameter direction is defined by the Func<> delegate itself, and you can't change it. Depending on what you're trying to do, you can define your own delegate apart from Func<>. Something like this, perhaps:brian.shapiro said:*snip*public delegate int MyDelegate(out char value);
Actually, I'm not 100% sure the above is valid. An "out" parameter on a delegate may not be valid. -
I think what you're looking for, to elaborate on what dpratt has written, is a new delegate along these lines:
public delegate void OutFunc<TIn, TOut> (TIn inParam, out TOut outParam);
-
That's a bad idea. Your delegate has 1 output value. It should be a regular function that RETURNS the output value. The .NET design guidelines state that ref- and out-parameters should only be used if there's no other option.Yggdrasil said:I think what you're looking for, to elaborate on what dpratt has written, is a new delegate along these lines:
public delegate void OutFunc<TIn, TOut> (TIn inParam, out TOut outParam);
-
What does the type have to do with the way how it is passed?brian.shapiro said:
evildictator,evildictaitor said:*snip*
The syntax shown in Visual Studio is Func<T, TResult> where T is a parameter.
Either way, it won't let me pass in a type parameter by reference. -
TommyCarlier said:
That's a bad idea. Your delegate has 1 output value. It should be a regular function that RETURNS the output value. The .NET design guidelines state that ref- and out-parameters should only be used if there's no other option.Yggdrasil said:*snip*Jeez, can't anybody focus on the issue at hand? Of course it's a pointless method signature, but it serves to illustrate the point of how to represent a generic delegate with an out param, which is what the original poster wanted. A technical question gets a technical answer.
Would you also like to correct my coding standards, because it's considered unnecessary to add the T prefix to the type definitions?
Thread Closed
This thread is kinda stale and has been closed but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.