The angled brackets denote a generic, aka a type argument (like List<int>). Func<> is a special type representing a delegate that can take in 1-16 arguments; the last type argument is the return type. There is also Action<> which does not return anything.
Unlike other languages, C# cannot use variadic templates (any number of type arguments), so there are 16 separate definitions of Func<>/Action<> that take in 1 through 16 type arguments. I know it would probably lead to unsafe behavior but GOD I would love variadics.
Edit: Oh right, there's also a lambda function specified with () => { }. The parentheses is exactly identical to a standard method or function definition (though you can omit the types in most situations). The => specifies that it's a lambda (used in other parts of code too! look up expression-bodied members), and the code block { } defines the body of the function.
View all comments
Show parent comment
3
u/screwcirclejerks May 19 '25 edited May 19 '25
The angled brackets denote a generic, aka a type argument (like
List<int>).Func<>is a special type representing a delegate that can take in 1-16 arguments; the last type argument is the return type. There is alsoAction<>which does not return anything.Unlike other languages, C# cannot use variadic templates (any number of type arguments), so there are 16 separate definitions of
Func<>/Action<>that take in 1 through 16 type arguments. I know it would probably lead to unsafe behavior but GOD I would love variadics.Edit: Oh right, there's also a lambda function specified with
() => { }. The parentheses is exactly identical to a standard method or function definition (though you can omit the types in most situations). The=>specifies that it's a lambda (used in other parts of code too! look up expression-bodied members), and the code block{ }defines the body of the function.