LinkedList.Add C# (CSharp) Method

Add() public method

public Add ( Object obj ) : void
obj Object
return void
    public void Add(Object obj)
    {
        LinkedListNode node = new LinkedListNode( obj );
        LinkedListNode ptrEnd = m_start;
        if ( ptrEnd == null )
        {
            m_start = node;
        }
        else
        {
            while( ptrEnd.next != null )
            {
                ptrEnd = ptrEnd.next;
            }
            ptrEnd.next = node;
            node.last = ptrEnd;
        }
        m_Count++;
    }
    public void Set( int index, Object obj )

Usage Example

        public static void Main()
        {
            LinkedList<int> testList = new LinkedList<int>();

            for (int i = 0; i < 10; i++)
            {
                testList.Add(i);
            }

            foreach (var number in testList)
            {
                Console.Write(number + ", ");
            }
            Console.WriteLine("Count={0}", testList.Count);

            testList.Remove(9);
            foreach (var number in testList)
            {
                Console.Write(number + ", ");
            }
            Console.WriteLine("Count={0}", testList.Count);

            testList.Add(1);
            foreach (var number in testList)
            {
                Console.Write(number + ", ");
            }
            Console.WriteLine("Count={0}", testList.Count);

            Console.WriteLine("First index of 1={0}", testList.FirstIndexOf(1));
            Console.WriteLine("Last index of 1={0}", testList.LastIndexOf(1));
        }
All Usage Examples Of LinkedList::Add