Questions tagged [using-directives]

The `using` directive, available in several languages including C# and C++, introduces members of a namespace into the current identifier search scope.

The C++ using directive allows the names in a namespace to be used without the namespace-name as an explicit qualifier. Of course, the complete, qualified name can still be used to improve readability.

// C++ Example:
using std::cout

The C# using directive is used to qualify namespaces and create namespace or type aliases. The scope of a using directive is limited to the file in which it appears.

// C# Example:
using System.Text;
using Project = PC.MyCompany.Project;

Creating an alias for a namespace or a type in C# is called a "using alias directive", and is illustrated in the code sample below:

namespace PC
{
    // Define an alias for the nested namespace. 
    using Project = PC.MyCompany.Project;
    class A
    {
        void M()
        {
            // Use the alias
            Project.MyClass mc = new Project.MyClass();
        }
    }
    namespace MyCompany
    {
        namespace Project
        {
            public class MyClass { }
        }
    }
}
289 questions
-2
votes
2 answers

What does it mean if a using directive is light blue in Visual Studio?

This is the code. I've tried rewriting it in a new program but it's the same problem as soon as I create a class the "using system" and the others appear in light blue as well as attributes.
-2
votes
1 answer

"using static" throwing error

I'm trying to use using static System.Console; rather than using System; so I only have to type out WriteLine("bla") vs Console.WriteLine("bla"). My code is as follows: using static System.Console; public class Program { public static void…
georgie__
  • 1
  • 3
-2
votes
1 answer

Referencing Namespaces in C# headers with using-directives

I want to have using codes like as shown below, for example: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Diagnostics; using System.IO; but this c# code below (taken from the question Command…
-5
votes
1 answer

what should i do for working with closedxml correctly in asp.net

I'm using gridview on my webform and I want to export data from SQL server to excel using asp.net c#, and I'm using ClosedXML.Excel but the error is The type or namespace name 'ClosedXML' could not be found (are you missing a using directive or…
Shakeel Ameer
  • 11
  • 1
  • 1
  • 8
1 2 3
19
20