C# Error CS0262 – Partial declarations of ‘type’ have conflicting accessibility modifiers

C# Compiler Error

CS0262 – Partial declarations of ‘type’ have conflicting accessibility modifiers

Reason for the Error

You’ll get this error in your C# code when you have defined the partial types and each one has in-consistent modifiers.

For example, lets try to compile the below code snippet.

using System;

namespace DeveloperPubNamespace
{
    public partial class class1
    {
    }

    internal partial class class1
    {
    }
    class Program
    {
        public static void Main()
        {
            Console.WriteLine("Welcome");
        }
    }
}

You’ll receive the error code CS0262 when you try to build the C# program because you have declared multiple partial classes “class1” but with different access modifiers- One with public and other one with internal.

Error CS0262 Partial declarations of ‘class1’ have conflicting accessibility modifiers DeveloperPublish C:\Users\Senthil\source\repos\ConsoleApp3\ConsoleApp3\Program.cs 5 Active

Solution

In C#, the modifiers for the partial declarations must be consistent. To fix the error code CS0262 in the above program, just ensure that both the partial declarations have the same access modifiers.

using System;

namespace DeveloperPubNamespace
{
    public partial class class1
    {
    }

    public partial class class1
    {
    }
    class Program
    {
        public static void Main()
        {
            Console.WriteLine("Welcome");
        }
    }
}

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