How to fix error "You can't pass property, indexer or dynamic member with out or ref parameter"

Hi Folks,

I happened to encounter this trouble while trying to pass 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 Program class and pass head variable reference instead Property.

       internal QNode head = null;

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

 

Reference: https://msdn.microsoft.com/en-us/library/14akc2c7.aspx