I am trying to understand specifically why it is neccessary to have this Where<TSource>
What does the type straight after Where tell you?
I understand the ‘this’ concept which means its an extension method but cannoth understand the type after Where
public static IEnumerable<TSource> Where<TSource>(
this IEnumerable<TSource> source,
Func<TSource, bool> predicate
)
Func<TSource, bool>is a pointer to a function which takesTSourceas parameter and returns boolean. For example if you had the following function:you could pass it as argument to the Where method if you had a list of
SomeType:You could also use an anonymous function which avoids you the need to declare another function explicitly:
UPDATE:
I seem to have misunderstood the question. The type after the name of the function
Where<TSource>indicates a generic function definition. It indicates that this function has a generic argument which can be of any type. So for example when you write:TSourceequalsSomeTypeand the compiler is capable of automatically inferring it from the delegate. You could specify it explicitly but it’s too much of a writing: