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

Dynamically loading style sheets based on Server Controls

I have a website that will need to load basic style components based on the model (determined on backend SQL server based on user input) The concept is that this website can contained parameterized look-and-feel components which are predefined…
sammarcow
  • 2,736
  • 2
  • 28
  • 56
0
votes
4 answers

Does inheritance also automatically "inherit" namespaces from its parent?

Just wanted to ask generic question about Namespaces. If class A inherits class B and doesn't explicitly reference (using) B's namespace, do I have to explicitly using B namespace in my calling code to call B's methods from an instance of A? Is this…
Ninja
  • 1,012
  • 3
  • 14
  • 29
0
votes
2 answers

Missing a using directive or an assembly reference error

Looks like I am missing a using directive or an assembly reference. I made a CSHTML page to show a bill to user. this is made as an empty page using TBL_Bill table. but I encounter an error while trying to read data from other tables such as…
Arya
  • 91
  • 1
  • 11
0
votes
1 answer

Telerik.Web.UI could not be found, yet in project references

I am trying to move some existing webforms over to a new Web Application project type and they make use of the Telerik AJAX UI controls. I have installed the Telerik package and gone through their configuration steps (i.e. Convert to Telerik Web…
webworm
  • 10,587
  • 33
  • 120
  • 217
0
votes
0 answers

Why does my IDE (Visual Studio Code) mark "using xy" directives as unneccessary even though i require them for compiling?

I want to compile and run some c# code, but it's not working due to the methods/classes not being found by referenced libraries. Even though i included the needed namespaces e.g. "using System.Collections.Generic;", they will be grey'd out and…
0
votes
0 answers

Is there any way to use the same shortcut for two commands in visual studio 2015?

I'm using Visual Studio 2015 and I want to press (Ctrl + K, Ctrl + D) and, then have my code formated and using directives sorted and remove unsued ones. In summary, Pressing (Ctrl + K, Ctrl + D) executes these two commands: Edit.RemoveAndSort…
0
votes
1 answer

using class local type definition in constructor declaration

I am trying to use a class local type definition in a constructor declaration. both the classes are templates, here is the code. template < typename T> class complexType { public: using value_type = T; complexType( T t )…
Ravikumar Tulugu
  • 1,702
  • 2
  • 18
  • 40
0
votes
2 answers

On "using" to abbreviate object definitions of generic type

I'm quite new to C# so I apologize if this has been asked before but I've done some searches and haven't found what I'm looking for. Specifically, I'm aware I can use the keyword using in the following manner to (in some way) mimic the use of…
0
votes
1 answer

Why does the name lookup does not stop when it finds the entity implicitly declared by using directive?

Here is the code example: #include using namespace std; namespace B { int ohoh=2; } namespace A { int ohoh=666; namespace C { //using B::ohoh;(as if declared by using directive) //why does the lookup not stops here? …
choxsword
  • 3,187
  • 18
  • 44
0
votes
1 answer

What's the use of #ifdef and #endif processor directives in iPhone?

I want to know about the use of #ifdef, #ifndef and #endif and which case, have to used those conditionals and what's the use of it? Whats the difference between the #ifdef and #ifndef? For eg: #define MY_Global #ifdef MY_Global // write some…
Pugalmuni
  • 9,350
  • 8
  • 56
  • 97
0
votes
0 answers

edit or add features to a minified angular app

I’d like to know if there is some ways to tweak an existing-already-minified-55000-lines-code ? I work on an app and I want to add some extra stuff: By adding new controller ? Or new directives? On the same js file or separate new js file ? It’s…
0
votes
1 answer

Drilldown charts in angular js using google charts directives

We are new to angularjs v4. We have a requirement of drilldown charts in google charts. We are using ng2-google-charts directives. We are able to find the select event and updated the data. but chart is not reloading. Could any one please help on…
0
votes
2 answers

How to use an alias type as a generic type parameter in C#

How do you pass an alias type defined by using to the generic class? I tried the following code: using ID = Int32; // it might be replaced with `String`. using CC = C; public class C { T id; } and there will be an error: Error CS0246 …
Mr. Ree
  • 871
  • 9
  • 20
0
votes
1 answer

Error: Type or namespace not found

My code there is a errors like "The type or namespace name 'ChannelData' could not be found (are you missing a using directive or an assembly reference?)" How I correct this.please give your help. class ProcessCSV { public static…
0
votes
4 answers

Why does adding a namespace alias in C# remove ambiguity?

I have two distinct namespaces, each with a Thing class: namespace First.Second.Third { public class Thing { } } namespace Fourth.Fifth.Sixth { public class Thing { } } Now I try to use Thing elsewhere, and of course the compiler complains…
rory.ap
  • 34,009
  • 10
  • 83
  • 174