C# Error
CS1763 – ‘{0}’ is of type ‘{1}’. A default parameter value of a reference type other than string can only be initialized with null
Reason for the Error & Solution
A default parameter value of a reference type other than string can only be initialized with null
Example
The following sample generates CS1763:
// CS1763.cs (0,0)
class Program
{
public void Goo<T, U>(T t = default(U)) where U : T
{
}
static void Main(string[] args)
{
}
}
This example generates CS1763 because the Goo<T,U> parameter is declared with a default value of default(U) when the type of the parameter is T, despite the constraint that U derive from base class T.
To correct this error
Changing default(U) to use the corresponding type argument corrects this error:
public void Goo<T, U>(T t = default(T)) where U : T
{
}