Namespaces Questions and Answers

Practice Mode
Showing 10 of 30 questions
Q21
What does the "using" directive do?
  • A It includes a file in the project
  • B It imports types from other namespaces
  • C It defines a new namespace
  • D It creates an alias for a type
Answer: Option B
Explanation: The using directive imports types from other namespaces, allowing you to use them without full qualification.
Q22
Which statement about namespace accessibility is correct?
  • A Namespaces can be private or internal
  • B Namespaces are always publicly accessible
  • C Namespaces can have access modifiers
  • D Namespaces inherit accessibility from parent
Answer: Option B
Explanation: Namespaces themselves don't have access modifiers; they are always publicly accessible.
Q23
How do you reference a class from the global namespace?
  • A root::ClassName
  • B global::ClassName
  • C base::ClassName
  • D system::ClassName
Answer: Option B
Explanation: The global:: prefix is used to explicitly reference types from the global namespace.
Q24
What is the relationship between namespaces and assemblies?
  • A One assembly equals one namespace
  • B Namespaces and assemblies are the same
  • C A namespace can span multiple assemblies
  • D Assemblies cannot contain multiple namespaces
Answer: Option C
Explanation: A single assembly can contain multiple namespaces, and a single namespace can span multiple assemblies.
Q25
Which of these correctly demonstrates namespace usage?
  • A using System; class Program { static void Main() { Console.WriteLine("Hello"); } }
  • B namespace MyApp { using System; class Program { } }
  • C import System; class Program { }
  • D Both A and B
Answer: Option D
Explanation: Proper namespace usage involves declaring namespaces and using directives to access types.
Q26
What is the effect of the "using" directive within a namespace declaration?
  • A It makes the directive global
  • B It limits the directive scope to that namespace
  • C It causes a compilation error
  • D It has no effect
Answer: Option B
Explanation: Using directives can be placed inside namespace declarations to limit their scope to that namespace.
Q27
How can you prevent namespace pollution?
  • A By using wildcard imports
  • B By using specific using directives
  • C By putting all code in one namespace
  • D By using global imports only
Answer: Option B
Explanation: Using specific using directives instead of wildcards and organizing code in appropriate namespaces prevents pollution.
Q28
What is namespace collision?
  • A When namespaces use too much memory
  • B When the same type exists in multiple imported namespaces
  • C When namespaces are too deeply nested
  • D When using directives are missing
Answer: Option B
Explanation: Namespace collision occurs when the same type name exists in multiple imported namespaces.
Q29
Which directive helps resolve namespace conflicts?
  • A namespace directive
  • B alias directive
  • C using directive with aliases
  • D conflict directive
Answer: Option C
Explanation: Namespace aliases using the using directive help resolve conflicts between same-named types.
Q30
What is the default namespace for a new C# console application?
  • A System
  • B Console
  • C The project name
  • D Global
Answer: Option C
Explanation: The default namespace is typically based on the project name in Visual Studio.
Questions and Answers for Competitive Exams Various Entrance Test