C# 11 (.NET 7) Introduced file scoped types:
namespace sampleNS
{
file class Maths
{
public int Add(int x, int y) => (x + y + 2);
public int Multiply(int x, int y) => (x * y * 2);
}
class Calculations
{
public int SomeCalculation(int x, int y)
{
Maths maths = new();
return maths.Add(maths.Add(x, y), maths.Multiply(x, y));
}
}
}
They’re only accessible within the same file. They cannot be in different namespaces