0
0
C Sharp (C#)programming~5 mins

Namespaces and using directives in C Sharp (C#) - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a namespace in C#?
A namespace is a way to organize code by grouping related classes, interfaces, and other types under a name. It helps avoid name conflicts and makes code easier to manage.
Click to reveal answer
beginner
What does the using directive do in C#?
The using directive allows you to use types from a namespace without writing the full namespace path every time. It makes code shorter and easier to read.
Click to reveal answer
intermediate
How do namespaces help prevent naming conflicts?
Namespaces create separate spaces for names. Two classes with the same name can exist in different namespaces without conflict because their full names include the namespace.
Click to reveal answer
beginner
What happens if you don't use a using directive for a namespace?
You must write the full name of the type including its namespace every time you use it. For example, System.Console.WriteLine() instead of just Console.WriteLine().
Click to reveal answer
beginner
Can you use multiple using directives in one file?
Yes, you can include many using directives at the top of a file to access types from different namespaces easily.
Click to reveal answer
What keyword do you use to include a namespace in a C# file?
Ainclude
Busing
Cnamespace
Dimport
Which of these is a correct way to use a class from a namespace without a using directive?
AConsole.WriteLine()
Busing System.Console
CWriteLine()
DSystem.Console.WriteLine()
What is the main purpose of namespaces?
ATo organize code and avoid name conflicts
BTo speed up program execution
CTo create variables
DTo define methods
Can two classes with the same name exist in a project if they are in different namespaces?
AYes, namespaces separate their names
BOnly if they are in the same file
CNo, class names must be unique across the project
DOnly if one is private
Where do you usually place using directives in a C# file?
AInside methods
BAt the end of the file
CAt the top of the file
DInside classes
Explain what a namespace is and why it is useful in C# programming.
Think about how you keep your desk organized with folders.
You got /3 concepts.
    Describe how the using directive helps when writing C# code.
    Imagine not having to write a long address every time you send a letter.
    You got /3 concepts.