In C, What is FuncT1, T2, and what is it for?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Func<T1, T2> is a C# generic delegate type, not a C language feature. It represents a method that takes one argument of type T1 and returns a value of type T2, which makes it a convenient standard way to pass behavior around without declaring a custom delegate for every small callback shape.
Read the Type Parameters Correctly
The rule for Func is simple:
- every type parameter except the last one is an input type
- the last type parameter is the return type
So Func<int, string> means “a function that takes an int and returns a string.”
That lambda matches the signature exactly: one int goes in, one string comes back.
Why Func Exists
Without Func, you would often end up declaring many tiny delegate types just to pass small pieces of logic around.
These two ideas are equivalent in shape:
and
The built-in form is shorter, familiar to most .NET developers, and heavily used across the framework.
Func Appears Everywhere in LINQ
One of the most common places you see Func is in LINQ, even when you do not write the type explicitly.
Where expects a function from item to bool, and Select expects a function from item to transformed output. The compiler usually infers the Func<...> types from the lambdas.
Pass Behavior into Your Own Methods
Func is especially useful when a method should accept a strategy or calculation.
This lets the caller choose the behavior without subclassing or writing a switch statement for every variation.
Compare Func, Action, and Predicate
C# has a few related delegate families:
- '
Func<...>returns a value' - '
Action<...>returns nothing' - '
Predicate<T>returnsboolfor one input'
If you need a result, Func is the standard delegate family.
Func Can Represent Async Work Too
Because Func is just a delegate type, it can also describe methods that return Task.
This pattern appears in retry helpers, lazy initialization, and dependency-injection factories.
Use It Where It Clarifies, Not Everywhere
Func is great for small, generic pieces of behavior. But not every domain concept should be represented as an anonymous delegate. If the operation has real business meaning, a named interface or named method may communicate intent better.
The practical rule is to use Func for convenience while keeping readability first.
Common Pitfalls
- Reading the type parameters in the wrong order and forgetting the return type is last.
- Assuming
Func<T1, T2>is related to the C language instead of C# delegates. - Using
Funcfor every behavior even when a named abstraction would be clearer. - Forgetting that captured local state inside lambdas can affect behavior unexpectedly.
- Confusing
FuncwithActionwhen no return value is actually needed.
Summary
- '
Func<T1, T2>is a C# generic delegate for one input and one return value.' - All type parameters except the last are inputs; the last is the result type.
- '
Funcis widely used in LINQ, callbacks, and dependency-injection patterns.' - Use
Actionwhen no value is returned andPredicate<T>for simple boolean tests. - '
Funcis useful, but named abstractions are sometimes better for domain clarity.'

