C# Error CS0052 – Inconsistent accessibility: field type ‘type’ is less accessible than field ‘field’

C# Compiler Error

CS0052 – Inconsistent accessibility: field type ‘type’ is less accessible than field ‘field’

Reason for the Error

You would receive this error when you have a field defined in a class where the type is not publicly accessible.

For example, try compiling the below code snippet.

class Student
{
}

public class DeveloperPublish
{
    public Student _Student;
  
    public static void Main() { 
    
    }
}

This will result with the compiler error because the Student class is defined as private and is being used as a property in the DeveloperPublish class.

Error CS0052 Inconsistent accessibility: field type ‘Student’ is less accessible than field ‘DeveloperPublish._Student’

Solution

Ensure that the type that you are using in the field is public. You can set the access-modifier of the Student class to public to fix this error.

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