C# Error CS0051 – Inconsistent accessibility: parameter type ‘type’ is less accessible than method

C# Compiler Error

CS0051 – Inconsistent accessibility: parameter type ‘type’ is less accessible than method ‘method’

Reason for the Error

You would receive this error when you are passing an object as a parameter and the type that is being passed has a private/internal access modifier.

For example, try compiling the below code snippet.

class Student
{
}

public class DeveloperPublish
{
    // This results with CS0051 error
    public static void UpdateStudent(Student oldStudent)  
    {
        
    }

    public static void Main() { 
    
    }
}

This will result with the compiler error because the Student class is defined as private and is being passed as parameter in another class which it doesn’t have access to.

C# Error CS0051 – Inconsistent accessibility: parameter type 'type' is less accessible than method 'method'

Error CS0051 Inconsistent accessibility: parameter type ‘Student’ is less accessible than method ‘DeveloperPublish.UpdateStudent(Student)’ ConsoleApp1 C:\Users\Senthil\source\repos\ConsoleApp1\ConsoleApp1\Program.cs

Solution

Ensure that the type that you are passing in as parameter is accessible. You can set the access-modifier of the Student class to public to fix this error.

C# Error CS0051 – Inconsistent accessibility: parameter type 'type' is less accessible than method 'method'

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