Namespaces Questions and Answers

Practice Mode
Showing 10 of 30 questions
Q11
What is the primary purpose of namespaces in C#?
  • A To improve performance
  • B To organize code and prevent naming conflicts
  • C To make code run faster
  • D To reduce memory usage
Answer: Option B
Explanation: Namespaces help organize code and prevent naming conflicts.
Q12
Which keyword is used to declare a namespace in C#?
  • A class
  • B namespace
  • C using
  • D import
Answer: Option B
Explanation: The namespace keyword is used to define a namespace in C#.
Q13
How do you use a class from another namespace without fully qualifying it?
  • A Using the import keyword
  • B Using the include directive
  • C Using the using directive
  • D It happens automatically
Answer: Option C
Explanation: The using directive allows you to use types from other namespaces without full qualification.
Q14
What happens if two namespaces contain classes with the same name?
  • A The code will not compile
  • B You must use fully qualified names or aliases
  • C The first namespace used takes precedence
  • D Visual Studio automatically resolves it
Answer: Option B
Explanation: You can use aliases or fully qualified names to resolve ambiguity between same-named classes in different namespaces.
Q15
Which of the following is the correct way to define a namespace?
  • A namespace MyNamespace;
  • B namespace MyNamespace {}
  • C class namespace MyNamespace
  • D def namespace MyNamespace
Answer: Option B
Explanation: Namespace declaration uses the namespace keyword followed by the namespace name and braces.
Q16
What is the global namespace in C#?
  • A A namespace that contains global variables
  • B The root namespace containing all other namespaces
  • C A namespace for global functions
  • D A special namespace for system classes
Answer: Option B
Explanation: The global namespace is the root namespace that contains all other namespaces and types.
Q17
How can you create a namespace alias in C#?
  • A alias MyAlias = My.Namespace;
  • B using MyAlias = My.Namespace;
  • C namespace MyAlias = My.Namespace;
  • D import MyAlias = My.Namespace;
Answer: Option B
Explanation: Namespace aliases are created using the using directive with an alias assignment.
Q18
Which of these is a valid namespace naming convention?
  • A MyApplication.DataAccess
  • B my_application_data_access
  • C MyApplication_DataAccess
  • D myApplication.dataAccess
Answer: Option A
Explanation: Namespaces typically use PascalCase and may contain multiple segments separated by dots.
Q19
What is the purpose of the "using static" directive?
  • A To import all members of a namespace
  • B To import static members of a class
  • C To make a class static
  • D To define static variables
Answer: Option B
Explanation: The using static directive imports static members of a class, allowing you to use them without class qualification.
Q20
How are nested namespaces typically declared?
  • A namespace Outer { namespace Inner {} }
  • B namespace Outer.Inner {}
  • C Both A and B
  • D Neither A nor B
Answer: Option C
Explanation: Nested namespaces can be declared using dot notation in a single namespace declaration.
Questions and Answers for Competitive Exams Various Entrance Test