public static string CommaSeparate
{
Im having difficulty in understanding it easily\fully...
My concerns are:-
Why are both T and U needed after CommaSeperate and not just T?
How and why is the Select method mapping to the Func delegate func, by simply s => func(s) ?
Regards
Steve
VulpesPosted Jan 9, 2013, 5:48 PM
VulpesPosted Jan 11, 2013, 2:22 PM
A type parameter is in effect a variable which can represent (subject to any constraints) any type at all.
However, it's possible to have generic methods where the type parameters aren't used in the parameter list or return type but are used in the body of the method. For example, consider the generic method in this program which returns the default value of the type parameter's actual type:
using System;
class Test
{
static object GetTypeString
{
return default(T);
}
static void Main()
{
Console.WriteLine(GetTypeString
Console.WriteLine(GetTypeString
Console.ReadKey();
}
}
Guest UserPosted Jan 11, 2013, 4:15 AM
So when exactly do extension methods with 2 type parameters ie
For example the Where extension method only has 1 type parameter but takes a func input parameter like so
public static IEnumerable
(
Is this because the return value of the func delegate is already defined as bool and therefore a second generic type parameter ie U isnt needed?
Regards
Steve