0Pricing
C# Academy · Lesson

Namespaces, using directives, global usings (note)

Organize types with namespaces, import namespaces with using (and aliases), avoid name collisions, and note that global using is newer than C# 6.

Namespaces, using directives, global usings (note) is a free C# Academy lesson on CoddyKit — lesson 2 of 3. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the C# Academy learning path, one of 3 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Namespaces & using: overview

Goal: Organize and import code.

  • namespace groups related types
  • using imports namespaces
  • Aliases resolve name clashes
  • global using is newer than C# 6 (info only)

Declare namespace & type

Define a namespace to group types; you can always use the fully qualified name to access a type.

using System;

namespace MyApp.Models
{
  public class User
  {
    public string Name { get; private set; }
    public User(string name) { Name = name; }
  }
}

public class Program
{
  public static void Main(string[] args)
  {
    // Fully-qualified name without using
    MyApp.Models.User u = new MyApp.Models.User("Ada");
    Console.WriteLine(u.Name);
  }
}

using directive basics

Add a using directive to import a namespace so you can use short type names.

using System;
using MyApp.Models; // import the namespace declared previously

namespace MyApp.Models
{
  public class User
  {
    public string Name { get; private set; }
    public User(string name) { Name = name; }
  }
}

public class Program
{
  public static void Main(string[] args)
  {
    // Short type name thanks to using
    User u = new User("Alan");
    Console.WriteLine(u.Name);
  }
}

Nested namespaces & FQNs

Namespaces can be nested. Use fully qualified names when you want to be explicit.

using System;

namespace Company
{
  namespace Billing
  {
    public class Invoice { public int Number; }
  }

  namespace Support
  {
    public class Ticket { public int Id; }
  }
}

public class Program
{
  public static void Main(string[] args)
  {
    Company.Billing.Invoice inv = new Company.Billing.Invoice();
    inv.Number = 1001;
    Company.Support.Ticket t = new Company.Support.Ticket();
    t.Id = 42;
    Console.WriteLine("Invoice " + inv.Number + ", Ticket " + t.Id);
  }
}

using alias

Use a using alias to disambiguate identical type names or to shorten long qualified names.

using System;

// Two classes with the same short name in different namespaces
namespace LibA { public class Logger { public string Name = "A"; } }
namespace LibB { public class Logger { public string Name = "B"; } }

// Create aliases to disambiguate
using ALogger = LibA.Logger;
using BLogger = LibB.Logger;

public class Program
{
  public static void Main(string[] args)
  {
    ALogger a = new ALogger();
    BLogger b = new BLogger();
    Console.WriteLine(a.Name + " & " + b.Name); // A & B
  }
}

Global using note & tips

Note: global using arrived in newer C# (not in C# 6). In C# 6, place using directives at the top of each file.

  • Group related types into clear namespaces.
  • Keep names short but meaningful.
  • Use aliases to resolve collisions.

using directive meaning

Quick check: What does a using directive at the top of a C# file do?

Recap

Recap: Use namespace to organize types and using to import them per file. Resolve collisions with aliases. Global using is a newer feature; in C# 6, keep usings at file top.

Frequently asked questions

Is the “Namespaces, using directives, global usings (note)” lesson free?

Yes — the full text of “Namespaces, using directives, global usings (note)” is free to read here on the web, and the C# Academy course includes 3 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the C# Academy course, upgrade to CoddyKit PRO.

What will I learn in “Namespaces, using directives, global usings (note)”?

Organize types with namespaces, import namespaces with using (and aliases), avoid name collisions, and note that global using is newer than C# 6. You practise C# Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start C# Academy?

No prior experience is required. C# Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 3, so you can start here or from the beginning and move at your own pace.

How long does the “Namespaces, using directives, global usings (note)” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this C# Academy lesson?

Yes. Every C# Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. public/internal/protected/private (with note on file)
  2. Namespaces, using directives, global usings (note)
  3. Partial types & files
← Back to C# Academy