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
1
vote
1 answer

What using directive do I use for Server.MapPath in a separate .cs file in WebMatrix?

I am trying to use Server.MapPath() in a separate .cs file in WebMatrix. I can get the method going fine by using HttpContext.Current.Server.MapPath("~/SomeDirectory/someFile.txt") but do I really have to type HttpContext.Current every time? Isn't…
VoidKing
  • 6,282
  • 9
  • 49
  • 81
1
vote
1 answer

Why can't I use using to disambiguate between base members variables?

In this simple class hierarchy I'm trying to get class C to disambiguate which x to use by telling it "using B::x" but this doesn't compile in G++ because it still can't figure out which x I mean in the function foo. I know using can be used to…
TimeHorse
  • 510
  • 3
  • 14
1
vote
1 answer

Converting GCC assembly code to armasm assembly code

I am trying to convert GCC assembly code to ARMASM assembly code can anyone please help me with this. The main problem is .req .unreq .qn.dn . I wanted to know the equivalents of the above directives. I tried ALIAS it did not work. .align …
Aurum
  • 77
  • 12
1
vote
1 answer

include and using declaration

using ::bb::cascades::Application; #include What do these two declaration mean? And are there any good tutorials which states the using directive/declaration deeply?Thanks.
Tahlil
  • 2,680
  • 6
  • 43
  • 84
1
vote
5 answers

Inheriting from classes

In C#, how many classes can you inherit from? When you write: using System.Web.UI; is that considered inheriting from a class?
DNR
  • 3,706
  • 14
  • 56
  • 91
1
vote
6 answers

C# using system.io not woking in my class but works in main

I am working on an issue I do not remember ever having before. I am using VS2012 C# When i add using System.IO; to my main program everything works fine, however when I add it to my class file it will not let me use all of the methods. using…
badtoy1986
  • 43
  • 6
0
votes
1 answer

what does "$" mean in this SSI conditional statement?

I was reading about SSI here. The first code example under the section Control Directives looks like this: What does the "$" sign mean? EOF, a function, get...??? Thanks!
Chris22
  • 1,973
  • 8
  • 37
  • 55
0
votes
2 answers

c++ using declaration keyword usage seen in the examples of Boost library

i have noticed that #include #include #include using boost::asio::ip::tcp; int main(int argc, char* argv[]){ .... } uses using boost::asio::ip::tcp and not using namespace where tcp is a…
Mafahir Fairoze
  • 697
  • 2
  • 9
  • 21
0
votes
0 answers

Import certain overloads of base class to private scope of derived

Using the using-directive I'm able to select a certain set of methods from the base class to put into a different access scope. Is this also possible for individual overloads of the method? Something like this: Demo #include class base…
glades
  • 3,778
  • 1
  • 12
  • 34
0
votes
0 answers

How can I reuse "type alias" in another project?

I have a project with some interfaces that contains some type alias in it, for example like below: namespace UsingTest { using MyType = System.Collections.Generic.List; public interface IUsingTest { MyType GetList(); …
sorosh_sabz
  • 2,356
  • 2
  • 32
  • 53
0
votes
1 answer

C# Razor using statements inconsistently require explicit curly brackets

I have a .NET Framework 4.7.2 web application. I am receiving the following yellow screen error from some of my Views and Partial Views but not all of them: Expected a "{" but found a "using". Block statements must be enclosed in "{" and "}". You…
bowserm
  • 1,046
  • 10
  • 25
0
votes
1 answer

c++ syntax error when specializing nested template of a template parameter

This is what I'm trying to do: template class A { public: using CA = T::C; }; class B { public: template struct C {}; }; int main() { A a; return 0; }; However, inexplicably (to me), this…
lequinne
  • 118
  • 8
0
votes
2 answers

How do I control what usings are made global in a C#10 / .NET6.0 project?

C#10 in .NET 6.0 supports a new feature called global using directive. It seems to do 2 things: When you have a namespace in the global using, you don't have to include the using ... for that namespace at the top of your *.cs files. Some namespaces…
Stefan
  • 919
  • 2
  • 13
  • 24
0
votes
1 answer

Aliasing a generic interface with a using alias directive

I am aware that it's not possible to alias a generic type (e.g. using Foo = Dictionary; is invalid), but that the generic type on the right must be closed (e.g. using Foo = Dictionary; will work). However, it seems like it's invalid to…
Ernest3.14
  • 1,012
  • 11
  • 21
0
votes
0 answers

Import of Unknown directives dbquery, sdl

I'm using Stepzen, it generated graphql files, however, all of them with errors: stepzen/index.graphql schema @sdl(files: ["postgresql/index.graphql"]) { query: Query } stepzen/postgresql/index.graphql type Query { getCommentList: [Comment] …
Bulatron
  • 1
  • 1