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

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