Reputation: 1385
What is the rationale that non-static inner classes can be declared within a static class?
public static class A
{
public class B
{
public B() { }
}
}
As compared to the fact that non-static members and functions cannot be declared within a static class.
Upvotes: 4
Views: 79
Reputation: 156978
What about multiple instances of B
? In that way, non-static classes nested in static classes are no different to regular non-static classes.
public static class A
{
public class B
{
public B() { }
}
private static B b1 = new B();
private static B b2 = new B();
}
See for a real-life example the static System.Linq.Enumerable
class, which contains some specific implementations as nested non-static classes.
Upvotes: 3