access-levels

How to restrict access to nested class member to enclosing class?

百般思念 提交于 2019-11-26 07:28:15
问题 Is it possible to specify that members of a nested class can be accessed by the enclosing class, but not other classes ? Here\'s an illustration of the problem (of course my actual code is a bit more complex...) : public class Journal { public class JournalEntry { public JournalEntry(object value) { this.Timestamp = DateTime.Now; this.Value = value; } public DateTime Timestamp { get; private set; } public object Value { get; private set; } } // ... } I would like to prevent client code from