I am converting Java into C# and have the following code (see discussion in Java Context about its use). One approach might be to create a separate file/class but is there a C# idom which preserves the intention in the Java code?
public class Foo {
// Foo fields and functions
// ...
private static class SGroup {
private static Map<Integer, SGroup> idMap = new HashMap<Integer, SGroup>();
public SGroup(int id, String type) {
// ...
}
}
}
All C# nested classes are like Java static nested classes:
C#:
Is like Java's:
In other words, an instance of
Inner
doesn't have an implicit reference to an instance ofOuter
.There isn't the equivalent of a Java inner class in C# though.
The accessibility rules are somewhat different between the two languages though: in C#, the code in the nested class has access to private members in the containing class; in Java it's the other way round.
You can have a static nested class in C#, according to Nested Classes.
Give this a look http://blogs.msdn.com/oldnewthing/archive/2006/08/01/685248.aspx
I am looking specifically at