Junior — Middle
Kas saaksite selgitada, mida tähendab termin 'Func' programmeerimise kontekstis?
sobes.tech AI
Vastus AI-lt
In C#, Func is a built-in delegate that represents a method with a return value and zero or more parameters. It allows passing methods as objects, which is convenient for functional programming.
The syntax of Func is generic: the last parameter indicates the return type, and the preceding ones are the input parameter types.
Example:
Func<int, int, int> sum = (a, b) => a + b;
int result = sum(3, 4); // result will be 7
Here, Func<int, int, int> is a delegate that takes two ints and returns an int. Func is often used to pass logic to methods, LINQ queries, etc.