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
0
votes
2 answers

Arduino how to use namespace?

I am using the Arduino IDE to write code and am trying to understand the namespace stuff. My thought is, is there a way to shorten the many places (in my code) where I have things like: Serial.print("a="); Serial.print(a); Serial.print(" b=");…
Harvey
  • 2,062
  • 2
  • 21
  • 38
0
votes
6 answers

How to avoid many using operators in every .cs file?

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; I have to put the above code in almost every .cs file. Is there any way to avoid it?
Sergey
  • 47,222
  • 25
  • 87
  • 129
0
votes
1 answer

The name TemplateSelector does not exist in the namespace

I get this error: Error 1 The name "TemplateSelector" does not exist in the namespace "using:MyApps" but I don't know why because when I create new project and paste the same code to him everything is working so problem is only in my old project.…
pavol.franek
  • 1,396
  • 3
  • 19
  • 42
0
votes
1 answer

How to filter an array using angular js

angular.module('harbinger'). directive('dossierList', function () { return { restrict:"EAC", template:'
Prashobh
  • 9,216
  • 15
  • 61
  • 91
0
votes
2 answers

Remove 'using System.Linq' statment from all C# pages

I have this source in all the c# pages using System; using System.Collections.Generic; using System.Linq; using System.Data; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; I want to REMOVE all the using…
Nave Tseva
  • 868
  • 8
  • 24
  • 47
0
votes
0 answers

Is it possible "Using with alias at runtime"?

namespace { using Itest = IMyInterface } Then I use the Itest for rest of code But as per new requirement, based on some conditions i need to set the alias at runtime. >Like using Itest = {pick at runtime}
PKS
  • 51
  • 1
  • 5
0
votes
1 answer

Are all using directives viewed the same way as using namespace std?

I've easily gotten myself into the habit of prefixing standard identifiers with std:: instead of sticking in a using namespace std;. However, I've started getting into C# and I've noticed that it's very normal to add in whatever using directives are…
chris
  • 60,560
  • 13
  • 143
  • 205
0
votes
2 answers

Using directive in Derived Class changes inheritance to Public

A very simple question but yet confusing: Why does a using directive change the inheritance!? This compiles with Comeau. I have read that a using directive (decleration?) makes the variable public, but why? What I want is just a nice method not to…
Gabriel
  • 8,990
  • 6
  • 57
  • 101
0
votes
3 answers

Why is the "using" directive still needed in C++11 to bring forward methods from the base class that are overloaded in the derived class

The example below gets the following compiled error: test.cpp: In function ‘int main(int, char**)’: test.cpp:26:8: error: no match for call to ‘(Derived) (p1&)’ test.cpp:14:8: note: candidate is: test.cpp:16:10: note: void Derived::operator()(const…
Jaime
  • 1,182
  • 2
  • 12
  • 29
-1
votes
1 answer

How below macro is working in c programming language?

Code: #include #define puts "%s C preprocessor" int main() { printf(puts, puts); return 0; } Output: %s C preprocessor C preprocessor See also... Can anyone explain me the logic behind this output? I tried to solve it,but I…
-1
votes
1 answer

static using doesn't recognize method name, saying the name does not exist in the current context

PLEASE NOTE: I am aware that a similar question has already been answered. It took me a while to find that question/answer because it assumes I recognized that it specifically involves extension methods, which I didn't at first. I was under the…
rory.ap
  • 34,009
  • 10
  • 83
  • 174
-1
votes
2 answers

distance calculation error in c++

#include #include #include using namespace std; int square(int a){ return a*a; } struct Point{ int x,y; }; int distance (const Point& a,const Point& b){ int k=(int)…
user466534
-1
votes
1 answer

Problems after commenting out "using namespace std;"

I'm new to C++ and I read that "using namespace std;" is considered bad practice. I used the following code to test if my compiler was c++14 compliant: #include #include using namespace std; auto add([](auto a, auto b){ return…
q-l-p
  • 4,304
  • 3
  • 16
  • 36
-1
votes
1 answer

Why to use @property in iOS app development

I searched on internet about the @property in iOS and got answers such no need to explicitly use setter and getter method. beside all these answer can u explain me what is exact benefit of using @propert in iOS app development. what its benefit and…
Nasir
  • 1,617
  • 2
  • 19
  • 34
-2
votes
2 answers

C++ "was not declared in this scope"

Heyo, basically I was writing this simple function to ask you how many cars you have, inputing the amount in the array, and assigning the names of the cars to the array aswell. Also made a for loop to make display it and it says it was not declared…
Sweep
  • 15
  • 2
1 2 3
19
20