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

Namespaces and using directives in C Sharp (C#) - Mini Project: Build & Apply

Choose your learning style9 modes available
Namespaces and using directives
📖 Scenario: You are organizing a small program that prints messages from different parts of a company. Each part has its own namespace to keep things tidy.
🎯 Goal: You will create namespaces and use using directives to access classes inside them easily. Finally, you will print messages from each namespace.
📋 What You'll Learn
Create two namespaces named Company.Sales and Company.Support
Inside each namespace, create a class named Message with a method GetMessage() that returns a string
Create a Program class with a Main method
Use using directives to access the Message classes from both namespaces
Print the messages returned by GetMessage() methods from both namespaces
💡 Why This Matters
🌍 Real World
In real software projects, namespaces keep code organized and prevent conflicts when many developers work together or when using third-party libraries.
💼 Career
Understanding namespaces and using directives is essential for writing clean, maintainable C# code in professional development environments.
Progress0 / 4 steps
1
Create namespaces and classes
Create two namespaces called Company.Sales and Company.Support. Inside each, create a class named Message with a method GetMessage() that returns the string "Sales department says hello!" for Company.Sales.Message and "Support department is here to help!" for Company.Support.Message.
C Sharp (C#)
Need a hint?

Use the namespace keyword to create namespaces. Inside each, define a public class Message with a GetMessage() method that returns the required string.

2
Add using directives
Add using Company.Sales; and using Company.Support; directives at the top of the file to access the Message classes easily.
C Sharp (C#)
Need a hint?

Place the using directives at the very top of the file before any namespace declarations.

3
Create Program class and call methods
Create a Program class with a Main method. Inside Main, create one object of Message from Company.Sales and one from Company.Support. Call their GetMessage() methods and store the results in variables salesMessage and supportMessage.
C Sharp (C#)
Need a hint?

Use the Program class with a Main method. Create objects for both Message classes. Use the full name Company.Support.Message for the support message object to avoid confusion.

4
Print the messages
Add Console.WriteLine statements to print the variables salesMessage and supportMessage inside the Main method.
C Sharp (C#)
Need a hint?

Use Console.WriteLine to print each message on its own line.