C# Error CS1678 – Parameter {0} is declared as type ‘{1}{2}’ but should be ‘{3}{4}’

C# Error

CS1678 – Parameter {0} is declared as type ‘{1}{2}’ but should be ‘{3}{4}’

Reason for the Error & Solution

Parameter ‘number’ is declared as type ‘type1’ but should be ‘type2’

This error occurs when the parameter type in an anonymous method is different from the declaration of the delegate you are casting the method to.

The following sample generates CS1678:

// CS1678  
delegate void D(int i);  
class Errors
{  
   static void Main()
   {  
      D d = delegate(string s) { };   // CS1678  
      // To resolve, use the following line instead:  
      // D d = delegate(int s) { };  
   }  
}  

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...