C# Error CS0261 – Partial declarations of ‘type’ must be all classes, all structs, or all interfaces

C# Compiler Error

CS0261 – Partial declarations of ‘type’ must be all classes, all structs, or all interfaces

Reason for the Error

You’ll get this error in your C# code when you have declared the partial type on different types of constructs in various places.

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

using System;

namespace DeveloperPubNamespace
{
    partial class class1
    {
    }

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

You’ll receive the error code CS0261 when you try to build the C# program because you have declared the class “class1” and applied partial modifier on it and simultaneously, you have also declared a struct with the same name and marked it as partial.

Error CS0261 Partial declarations of ‘class1’ must be all classes, all record classes, all structs, all record structs, or all interfaces DeveloperPublish C:\Users\Senthil\source\repos\ConsoleApp3\ConsoleApp3\Program.cs 9 Active

C# Error CS0261 – Partial declarations of 'type' must be all classes, all structs, or all interfaces

Solution

You can fix this error in your C# program by ensuring that partial declarations is made for the same type.

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