What's the accessibility of Public Properties in a Private Class?

Viewed 69

If I have a class defined as below, what's the accessibility of the Value property within the private nested Node class?

public class LinkedList {
    private class Node {
        public int Value { get; set;}
        public Node Next { get; set;}
    }
}

Can anyone answer when possibly would you consider to do this? What's the implication of this class definition?

1 Answers

You'd do this when Node is required to facilitate the LinkedList class in achieving its purpose/goals.

The implication of the class definition is that only the LinkedList class can create instances of Node.

Of course, LinkedList can also see the public properties of those instances of Node, including the Value property.

Related