Public Inner Classes

Can someone explain why we can do this and why we need it?

public class OuterClass
{
  public class InnerClass 
  {
  }
}

Why do we need a public inner everything: struct, class, enum or static class?

I think that if it is internal, it should only be closed or protected.

+5
source share
4 answers

Usually you do not need public nested types, but sometimes they can be useful. They make clear that one type is clearly related to another.

( #), . , List<T>.Enumerator , . Java - - .

, , , . , , , (, ).

+12

:

public class TrainingFile {

    public List<TrainingFileEntry> getEntries() {
           return ...
    }

    public class TrainingFileEntry {
        int x;
        int y;
   }
}

TrainingFileEntry, . Ofc , ist "" , . -)

+2

, InnerClass . , OuterClass , InnerClass .

0

All Articles