ExtensionMethod.NET Home of 880 C#, Visual Basic, F# and Javascript extension methods

Apply a function

applies a function to the given value - best used with static methods

Source

public static B Apply<A, B>(this A a, System.Func<A, B> f)
{
  return f(a);
}

Example

"Hello".Apply(System.String.IsNullOrWhiteSpace); // = false
"3".Apply(System.Int32.Parse);                   // = 3 (Int32)

Author: Carsten König

Submitted on: 28 feb. 2014

Language: C#

Type: generic

Views: 5359