Creating delegates manually vs using Action/Func delegates

The advent of Action and Func family of delegates has rendered custom delegates less used, but the latter still finds uses. Advantages of custom delegates include: As others have pointed, conveys intent clearly unlike generic Action and Func (Patrik has a very good point about meaningful parameter names). You can specify ref/out parameters unlike the … Read more

Go map of functions

Are you trying to do something like this? I’ve revised the example to use varying types and numbers of function parameters. package main import “fmt” func f(p string) { fmt.Println(“function f parameter:”, p) } func g(p string, q int) { fmt.Println(“function g parameters:”, p, q) } func main() { m := map[string]interface{}{ “f”: f, “g”: … Read more

Explanation of Func

Are you familiar with delegates in general? I have a page about delegates and events which may help if not, although it’s more geared towards explaining the differences between the two. Func<T, TResult> is just a generic delegate – work out what it means in any particular situation by replacing the type parameters (T and … Read more

Delegates: Predicate vs. Action vs. Func

Predicate: essentially Func<T, bool>; asks the question “does the specified argument satisfy the condition represented by the delegate?” Used in things like List.FindAll. Action: Perform an action given the arguments. Very general purpose. Not used much in LINQ as it implies side-effects, basically. Func: Used extensively in LINQ, usually to transform the argument, e.g. by … Read more

Func with out parameter

ref and out are not part of the type parameter definition so you can’t use the built-in Func delegate to pass ref and out arguments. Of course, you can declare your own delegate if you want: delegate V MyDelegate<T,U,V>(T input, out U output);

Why Func instead of Predicate?

While Predicate has been introduced at the same time that List<T> and Array<T>, in .net 2.0, the different Func and Action variants come from .net 3.5. So those Func predicates are used mainly for consistency in the LINQ operators. As of .net 3.5, about using Func<T> and Action<T> the guideline states: Do use the new … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)