C# Error CS0764 – Both partial method declarations must be unsafe or neither may be unsafe

C# Error

CS0764 – Both partial method declarations must be unsafe or neither may be unsafe

Reason for the Error & Solution

Both partial method declarations must be unsafe or neither may be unsafe

A partial method consists of a defining declaration (signature) and an optional implementing declaration (body). If the defining declaration has the unsafe modifier, the implementing declaration must also have it. Conversely, if the implementing declaration has the unsafe modifier, the defining declaration must also.

To correct this error

  1. Assuming that the defining declaration is correct, add or remove the unsafe modifier from the implementing declaration to match the defining declaration.

Example

// cs0764.cs  
//  Compile with: /target:library /unsafe  
public partial class C  
{  
    partial void Part();  
    unsafe partial void Part() //CS0764  
    {  
    }  
  
    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...