What is a namespace in C#

A namespace in C# is a container that holds a set of related classes, interfaces, structs, enums, and delegates. It is used to organize code and to prevent name conflicts. Namespaces provide a way to differentiate classes that may have the same name but are located in different libraries or projects.

For example, the System namespace contains fundamental classes and base classes that define commonly-used data types, events, and event handlers. You can create your own namespaces by using the "namespace" keyword followed by the namespace name.

Here’s an example of how to define and use a namespace in C#:

namespace MyApplication { class Program { static void Main(string[] args) { Console.WriteLine("Hello, World!"); } } }

namespace C# organization code classes interface structs