← Back to C# Course | Chapter 1: Setup & Basics | Lesson 6 of 7

Namespaces

In this page:

  1. Namespaces

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

markup
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));
        }
    }
}
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.