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

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