Skip to content
AgileLogics
3 min read

Namespaces

Prerequisites: Static members

A namespace groups related types, avoiding name collisions between libraries — C#'s equivalent of a Java package.

namespace MyApp.Models {
    public class User {
        public string Name = "";
    }
}

using MyApp.Models;

var user = new User();

Modern C# also supports file-scoped namespaces (namespace MyApp.Models; with no braces), reducing one level of indentation for every file.