C# Error CS1728 – Cannot bind delegate to ‘{0}’ because it is a member of ‘System.Nullable

C# Error

CS1728 – Cannot bind delegate to ‘{0}’ because it is a member of ‘System.Nullable

Reason for the Error & Solution

Cannot bind delegate to ‘member’ because it is a member of ‘type’

You cannot bind delegates to members of Nullable value types.

Example

The following sample generates CS1728:

// CS1728.cs  
class Test  
{  
   delegate T GetT<T>();  
   delegate T GetT1<T>(T t);  
  
   delegate bool E(object o);  
   delegate int I();  
   delegate string S();  
  
   static void Main()  
   {  
      int? x = null;  
      int? y = 5;  
  
      GetT<int> d1 = x.GetValueOrDefault;   // CS1728  
      GetT<int> d2 = y.GetValueOrDefault;   // CS1728  
      GetT1<int> d3 = x.GetValueOrDefault;   // CS1728  
      GetT1<int> d4 = y.GetValueOrDefault;   // CS1728  
   }  
}  

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

C# Compiler Error CS0442 – ‘Property’: abstract properties cannot have private accessors Reason for the Error You’ll get this error...
This is a really simple one . Below is a simple example of an enum called “Designation” defined with the...
This blog post explain the usage of the Checked Block in .NET and how you can use them in Visual...