Fix: Error "You can't Pass Property, Indexer or Dynamic Member with Out or Ref Parameter"

I happened to encounter this trouble while trying to pass the reference of a Property.

public class LinkedListQ : QNode

{

    private QNode head = null;

    public QNode Head

   {

      get

     {

        return head;

     }

}

class Program

{

   static void Main(string[] args)

{

LinkedListQ que = new LinkedListQ();

que.ReverseList(ref que.Head); //Error "A property, indexer or dynamic member access may not be passed as an out or ref parameter"

}

 
The reason as per MSDN is - Properties are not variables. They are methods, and cannot be passed to ref parameters.

The workaround I figured out is to change the head variable to internal in order to be accessible from the Program class and pass the head variable reference instead of the Property.

internal QNode head = null;

que.ReverseList(ref que.head); //Works fine

Reference: C# Reference