Namespaces and where classes live
A namespace is a surname for a group of classes. It lets two classes share a simple name without clashing.
Your classes and the framework classes
The framework ships thousands of classes, grouped into namespaces by purpose. Your classes live in a namespace you choose. A using statement at the top of a file saves you from typing the full name every time.
C#
using System;
using System.Collections.Generic;
namespace MyPractice
{
public class Lesson { }
}Why it matters
- Two libraries can both define a class called Item without conflict.
- A clear namespace tells a reader what part of a system a class belongs to.
- Using statements keep your code short while staying unambiguous.
When a name is ambiguous. If two using statements bring in the same class name, the compiler asks you to be specific. Type the full name once to resolve it.
With names settled, add more detail to a class in a second class with more detail.