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