Nullable Func<T, TResult>

That doesn't make sense.
All reference types, including Func<...>, can already be null.

Nullable types apply to value types (structs), which cannot ordinarily be null.


A Func is a delegate which is a reference type. This means it is already nullable (you can pass null to a method).


Func -> Encapsulates a method that returns a type specified by generic parameter

If return type is void, There is a different delegate (Action)

Action ->Encapsulates a method that does not return a value.

If you require Func to accept parameters that can accept null (nullable type), or require Func to return value which may be null(nullable type), there is no restriction.

For Example.

    Func<int?, int?, bool> intcomparer = 
    (a,b)=>
    {
    if(a.HasValue &&b.HasValue &&a==b) 
        return true;
        return false;
    } ;

    Func<int?, int?, bool?> nullintcomparer = 
    (a,b)=>
    {

    if(a.HasValue &&b.HasValue &&a==b) 
        return true;
    if(!a.HasValue || !b.HasValue)
       return null;
        return false;
    } ;

    var result1 = intcomparer(null,null); //FALSE
    var result2 = intcomparer(1,null); // FALSE
    var result3 = intcomparer(2,2); //TRUE


    var result4 = nullintcomparer(null,null); // null
    var result5 = nullintcomparer(1,null); // null
    var result6 = nullintcomparer(2,2); //TRUE

Tags:

C#

Func