Namespaces
In this page:
Namespaces
Namespaces group related classes together and prevent naming collisions between libraries. You declare your own namespace with the namespace keyword, and pull in others with using. Large C# codebases rely heavily on namespaces to stay organized.
Note: Namespace names conventionally follow a dotted, PascalCase pattern like Company.Product.Module.
Example: Namespaces
using System;
namespace MyApp.Utilities
{
class MathHelper
{
public static int Square(int n) => n * n;
}
}
namespace MyApp
{
using MyApp.Utilities;
class Program
{
static void Main(string[] args)
{
Console.WriteLine(MathHelper.Square(5));
}
}
}
Login to try C/C++/Java/PHP code in the editor
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: