HomeCSharpC# Error CS0755 – Both partial method declarations must be extension methods or neither may be an extension method

C# Error CS0755 – Both partial method declarations must be extension methods or neither may be an extension method

C# Error

CS0755 – Both partial method declarations must be extension methods or neither may be an extension method

Reason for the Error & Solution

Both partial method declarations must be extension methods or neither may be an extension method.

A partial method consists of a defining declaration (signature) and an optional implementing declaration (body). If the defining declaration is an extension method, the implementing declaration, if one is defined, must also be an extension method. And if the defining method is not an extension method, the implementing must not be one either.

To correct this error

  1. Either remove the this modifier from one of the parts, or add it to the other.

Example

The following example generates CS0755:

// cs0755.cs  
    public static partial class Ext  
    {  
        static partial void Part(this C c); //Extension method  
  
        // Typically the implementing declaration is in a separate file.  
        static partial void Part(C c) //CS0755  
        {  
        }  
    }  
  
    public partial class C  
    {  
        public static int Main()  
        {  
            return 1;  
        }  
    }  

Leave A Reply

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

You May Also Like

This C# program calculates and displays an upper triangular matrix based on user input. Problem Statement: The program takes the...
This C# program serves as a demonstration of bitwise operators, which are fundamental operators used for manipulating individual bits in...
This C# program is designed to interchange or swap the columns of a matrix. A matrix is a two-dimensional array...