C# Error CS0138 – A using namespace directive can only be applied to namespaces

Compiler Error

CS0138 – A using namespace directive can only be applied to namespaces; ‘type’ is a type not a namespace

Reason for the Error

You will receive this error in C# when you use a class instead of the namespace as parameter when using keyword is used.

In the below code, we are trying to import System.Console with the using keyword which results in the CS0138 error.

using System.Console;
namespace DeveloperPublishNamespace
{
    public class DeveloperPublish
    {
        public static void Main()
        {
        }
    }

}

Error CS0138 A ‘using namespace’ directive can only be applied to namespaces; ‘Console’ is a type not a namespace. Consider a ‘using static’ directive instead ConsoleApp1 C:\Users\Senthil\source\repos\ConsoleApp1\ConsoleApp1\Program.cs 1 Active

Solution

To fix the error code CS0138, ensure that you use the namespace as parameter when the using directive is used in C#.

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