Skip to content

Latest commit

 

History

History
40 lines (34 loc) · 1.08 KB

cs0403.md

File metadata and controls

40 lines (34 loc) · 1.08 KB
description title ms.date f1_keywords helpviewer_keywords ms.assetid
Compiler Error CS0403
Compiler Error CS0403
07/20/2015
CS0403
CS0403
6e5d55ce-d6bf-419d-aded-aaa2e5963bb6

Compiler Error CS0403

Cannot convert null to type parameter 'name' because it could be a non-nullable value type. Consider using default('T') instead.

You cannot assign null to the unknown type named because it might be a value type, which does not allow null assignment. If your generic class is not intended to accept value types, use the class type constraint. If it can accept value types, such as the built-in types, you may be able to replace the assignment to null with the expression default(T), as shown in the following example.

Example

The following sample generates CS0403.

// CS0403.cs  
// compile with: /target:library  
class C<T>  
{  
   public void f()  
   {  
      T t = null;  // CS0403  
      T t2 = default(T);   // OK  
    }  
}  
  
class D<T> where T : class
{  
   public void f()  
   {  
      T t = null;  // OK  
    }  
}