Exemplo n.º 1
0
 public void PrintToScreen()
 {
     Console.WriteLine(content);
     if (next != null)
     {
         next.PrintToScreen();
     }
 }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            listElement headOfList = new listElement();
            // Instantiate the tail of the list:
            listElement tailOfList = new listElement();

            headOfList.SetData("Element 1");

            // Set the new instance to the head of the list, so that the tail
            // can be defined:

            tailOfList = headOfList;

            // Append element to the end of the list. With each append the
            // instance tailOfList is set to the newly formed list element,
            // by means of returning the value:

            for (int element = 2; element < 5; element++)
            {
                tailOfList = tailOfList.AppendElement("Element " + element);
            }

            headOfList.PrintToScreen();

            string inputString;

            do
            {
                Console.WriteLine("Give a new element number (99 to abort): ");
                inputString = Console.ReadLine();

                // Append the new list element and determine the end of the list:
                tailOfList = tailOfList.AppendElement("Element " + inputString);

                Console.WriteLine("Tail of list after appending:");
                tailOfList.PrintToScreen();

                // Append the new list element:
                Console.WriteLine("Print from head of list after appending:");
                headOfList.PrintToScreen();
            }while (inputString != "99");
        }