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