title: How to return instance of a nested private class in C# using public method of the outer class?
body: <p>I am implementing a Linked list in C#. I created a <strong>Node</strong> class and a <strong>MyLinkedList</strong> class. Node class implements the node having properties <strong>Key</strong> and <strong>Next</strong>. MyLinkedList class implements all the operations such as <strong>Insert</strong>, <strong>Find</strong>, <strong>Update</strong>, <strong>Remove</strong> etc and two properties <strong>Head</strong> and <strong>Count</strong>.</p>
  <p>I don't want the user to create Node instances from outside of the MyLinkedList class so I nested the Node class inside MyLinkedList class making it private.
  Now, in the implemetation of Find method I am unable to return the Node type.
  I am also not able to give public access to Head property of outer class which is also a Node instance.</p>
  <p><strong>Summary: Basically, the problem is I want to prevent user from making an object of nested private class anywhere outside of it's enclosing class but it also limits the enclosing class ability to return it's nested private class' instance in the process.</strong></p>
  <pre><code>public class MyLinkedList&lt;T&gt;
      {
          public Node&lt;T&gt; Head { get; set; } //Error: Inconsistent accessibility: property type 'MyLinkedList&lt;T&gt;.Node&lt;T&gt;' is less accessible than property 'MyLinkedList&lt;T&gt;.Head'
          public int Count { get; set; }
  
          public MyLinkedList()
          {
              this.Head = null;
              this.Count = 0;
          }
          public Node&lt;T&gt; Find(T value)//Error: Inconsistent accessibility: property type 'MyLinkedList&lt;T&gt;.Node&lt;T&gt;' is less accessible than method 'MyLinkedList&lt;T&gt;.Find(T)'
          {
              Node&lt;T&gt; curr = this.Head;
              while (!(curr is null) &amp;&amp; !curr.Data.Equals(value))
              {
                  curr = curr.Next;
              }
              if (curr == null) return null;
              return curr;
          }
          private class Node&lt;K&gt;
          {
              public K Data { get; set; }
              public Node&lt;K&gt; Next { get; internal set; }
              public Node(K data)
              {
                  this.Data = data;
                  this.Next = null;
              }
          }
       }
  </code></pre>