Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does func ACTUALLY work

Tags:

c#

func

So when I return an object, under the covers I think it's returning the memory address to that object (or an object containing the memory address) which you can reference and use.

But what is actually happening when you return a func?

How does your app know which instance of an object to use with that func?

My instinct tells me that an object instance reference is passed along with the func but is that what is actually happening?

I can't seem to find much on this topic.

Edit: To clarify, I am asking when a method returns a func

like image 371
Anthony Russell Avatar asked Dec 12 '13 20:12

Anthony Russell


People also ask

How does Func work C#?

A Func in C# is a way to define a method in-line that has a return value. There is a similar concept of an Action that doesn't have a return value, but we'll get to that in a sec. The return value's type is always the last generic parameter on the Func 's definition.

How do you use func?

The following example uses Func to add values. int Sum(int x, int y) { return x + y; } Func<int, int, int> add = Sum; int res = add(150, 10); Console. WriteLine(res); We have a Sum method which adds two values.

What is func function?

Declares an extension function that is visible everywhere.

What are Func and Action Why do we use?

Action is a delegate (pointer) to a method, that takes zero, one or more input parameters, but does not return anything. Func is a delegate (pointer) to a method, that takes zero, one or more input parameters, and returns a value (or reference).


1 Answers

A Func is a delegate -- a type of object that is associated with a specific method signature and is usually bound to a specific method with that signature. This might be either a static or an instance method and it might be generic or not; in all cases, the delegate instance holds all the information required to call the method.

like image 83
Jon Avatar answered Oct 18 '22 23:10

Jon