Func<T, TResult> Delegate
public delegate TResult Func<in T, out TResult>( T arg )
- in T
The type of the parameter of the method that this delegate encapsulates.This type parameter is contravariant. That is, you can use either the type you specified or any type that is less derived. For more information about covariance and contravariance, see Covariance and Contravariance in Generics.
- out TResult
The type of the return value of the method that this delegate encapsulates.This type parameter is covariant. That is, you can use either the type you specified or any type that is more derived. For more information about covariance and contravariance, see Covariance and Contravariance in Generics.Parameters
- arg
- Type: T
The parameter of the method that this delegate encapsulates.Return Value
Type: TResult The return value of the method that this delegate encapsulates.When you use the Func<T, TResult> delegate, you do not have to explicitly define a delegate that encapsulates a method with a single parameter. For example, the following code explicitly declares a delegate named ConvertMethodand assigns a reference to the UppercaseString method to its delegate instance.using System; delegate string ConvertMethod(string inString); public class DelegateExample { public static void Main() { // Instantiate delegate to reference UppercaseString method ConvertMethod convertMeth = UppercaseString; string name = "Dakota"; // Use delegate instance to call UppercaseString method Console.WriteLine(convertMeth(name)); } private static string UppercaseString(string inputString) { return inputString.ToUpper(); } }
No comments:
Post a Comment