HomeCSharpC# Error CS0118 – construct1_name’ is a ‘construct1’ but is used like a ‘construct2’

C# Error CS0118 – construct1_name’ is a ‘construct1’ but is used like a ‘construct2’

C# Compiler Error

CS0118 – construct1_name’ is a ‘construct1’ but is used like a ‘construct2’

Reason for the Error

You will receive this error when you perform a disallowed operation on a construct. For example, the namespaces in C# cannot be instantiated but what happens when you try to instantiate an namespace? You will receive the compiler error CS0118 in C#.

Below is a code snippet demonstrating this error.

namespace DeveloperPublishNamespace
{
    public class Class1
    {
        public int MyProperty { get; set; }
    }

    public class DeveloperPublish
    {
        public static void Main()
        {
            DeveloperPublishNamespace obj = new DeveloperPublishNamespace();
        }
    }
}

Error CS0118 ‘DeveloperPublishNamespace’ is a namespace but is used like a type ConsoleApp1 C:\Users\Senthil\source\repos\ConsoleApp1\ConsoleApp1\Program.cs 12 Active

C# Error CS0118 – construct1_name' is a 'construct1' but is used like a 'construct2'

Solution

To fix the error code CS0118, ensure that the operation that you are performing is valid for the type that you are using. For example, use the class instead of the namespace for the above example.

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