Questions tagged [func]

Func is a family of delegate types in the .Net framework.

Func is a family of types in the framework. They are in the System namespace and can be used to represent a function that returns a value and has zero or more parameters.

1154 questions
863
votes
3 answers

Func vs. Action vs. Predicate

With real examples and their use, can someone please help me understand: When do we need a Func delegate? When do we need an Action delegate? When do we need a Predicate delegate?
InfoLearner
  • 14,952
  • 20
  • 76
  • 124
238
votes
14 answers

"undefined" function declared in another file?

I'm trying to write a basic go program that calls a function on a different file, but a part of the same package. However, it returns: undefined: NewEmployee Here is the source code: main.go: package main func main() { emp := NewEmployee() …
Juan M
  • 4,063
  • 4
  • 19
  • 28
231
votes
4 answers

Why Func instead of Predicate?

This is just a curiosity question I was wondering if anyone had a good answer to: In the .NET Framework Class Library we have for example these two methods: public static IQueryable Where( this IQueryable source, …
Svish
  • 152,914
  • 173
  • 462
  • 620
199
votes
4 answers

Func with out parameter

Can I pass a method with an out parameter as a Func? public IList FindForBar(string bar, out int count) { } // somewhere else public IList Find(Func> listFunction) { } Func needs a type so out won't compile there, and…
blu
  • 12,905
  • 20
  • 70
  • 106
159
votes
10 answers

Delegates: Predicate vs. Action vs. Func

Can someone provide a good explanation (hopefully with examples) of these 3 most important delegates: Predicate Action Func
Sasha
142
votes
9 answers

converting a .net Func to a .net Expression>

Going from a lambda to an Expression is easy using a method call... public void GimmeExpression(Expression> expression) { ((MemberExpression)expression.Body).Member.Name; // "DoStuff" } public void SomewhereElse() { …
Dave Cameron
  • 2,110
  • 2
  • 19
  • 23
120
votes
2 answers

Func() vs Func.Invoke()

I'm curious about the differences between calling a Func directly vs. using Invoke() on it. Is there a difference? Is the first syntactical sugar and calls Invoke() underneath anyway? public T DoWork(Func method) { return…
tris
  • 1,780
  • 3
  • 18
  • 28
110
votes
12 answers

How to make a random color with Swift

How I can make a random color function using Swift? import UIKit class ViewController: UIViewController { var randomNumber = arc4random_uniform(20) var randomColor = arc4random() //Color Background randomly func colorBackground()…
Giovanie Rodz
  • 1,741
  • 3
  • 12
  • 7
91
votes
4 answers

Explanation of Func

I was wondering if someone could explain what Func is and how it is used with some clear examples.
zSynopsis
  • 4,854
  • 21
  • 69
  • 106
81
votes
7 answers

Go map of functions

I have Go program that has a function defined. I also have a map that should have a key for each function. How can I do that? I have tried this, but this doesn't work. func a(param string) { } m := map[string] func { 'a_func': a, } for key,…
Conceited Code
  • 4,517
  • 3
  • 29
  • 32
79
votes
8 answers

Creating delegates manually vs using Action/Func delegates

Today I was thinking about declaring this: private delegate double ChangeListAction(string param1, int number); but why not use this: private Func ChangeListAction; or if ChangeListAction would have no return value I could…
Elisabeth
  • 20,496
  • 52
  • 200
  • 321
76
votes
2 answers

Func delegate with ref variable

public object MethodName(ref float y) { // elided } How do I define a Func delegate for this method?
chugh97
  • 9,602
  • 25
  • 89
  • 136
73
votes
9 answers

How do you use Func<> and Action<> when designing applications?

All the examples I can find about Func<> and Action<> are simple as in the one below where you see how they technically work but I would like to see them used in examples where they solve problems that previously could not be solved or could be…
Edward Tanguay
  • 189,012
  • 314
  • 712
  • 1,047
68
votes
6 answers

Can you get a Func (or similar) from a MethodInfo object?

I realize that, generally speaking, there are performance implications of using reflection. (I myself am not a fan of reflection at all, actually; this is a purely academic question.) Suppose there exists some class that looks like this: public…
Dan Tao
  • 125,917
  • 54
  • 300
  • 447
58
votes
5 answers

Array and slice data types

I found myself confused with the array and slice data types. From Go docs, arrays are described as follows: There are major differences between the ways arrays work in Go and C. In Go, Arrays are values. Assigning one array to another copies all…
duganets
  • 1,853
  • 5
  • 20
  • 31
1
2 3
76 77