Using a namespace contained in a library: choose the correct sequence to make its elements available in your project.
-
AAdd a reference to the namespace. Use the elements of the namespace directly.
-
BAdd a reference to the assembly that contains the namespace. Import the namespace with a using directive. Use its elements.
-
CImport the namespace with a using directive only. Use its elements without adding any reference.
-
DCopy the library file next to the project and start using the elements without referencing it.
-
EInstall the namespace in the Global Assembly Cache (GAC) to start using its elements automatically.
Answer
Correct Answer: Add a reference to the assembly that contains the namespace. Import the namespace with a using directive. Use its elements.
Explanation
Introduction / Context:To consume types from an external library, you must reference the assembly and optionally add using directives. This question checks the exact order of operations.
Given Data / Assumptions:
- Types live in assemblies; namespaces are logical groupings within those assemblies.
- Referencing assemblies differs from adding using directives.
Concept / Approach:Reference resolves the binary dependency; using resolves name lookup convenience within source code. Without the reference, the compiler/linker cannot locate the types, regardless of usings.
Step-by-Step Solution:
Step 1: Add the assembly reference (Project → Add Reference).Step 2: Add a using directive to shorten type names (optional if you use fully qualified names).Step 3: Use the types in code.Verification / Alternative check:Try to compile with only using and no reference; the build fails because the type is unresolved.
Why Other Options Are Wrong:A confuses namespaces with assemblies; C misses the required reference; D is not sufficient; E is unnecessary for most scenarios and does not by itself wire references.
Common Pitfalls:Believing using imports binaries, or thinking copying the DLL beside the EXE is enough without adding a reference.
Final Answer:Add a reference to the assembly that contains the namespace. Import the namespace with a using directive. Use its elements.