Linked list operations in C#

Linked list is a linear collection data set where One node pointing to other node.
While adding new value to Linked List we can directly add First, add Last, adding after Specific Node and Adding before Specific node.

linkedlstobj.AddFirst(Value);
linkedlstobj.AddLast(value);
linkedlstobj.AddBefore(node, value);
linkedlstobj.AddAfter(node, value);

To get the Node from Linked List we need to pass the value and output datatype LinkedListNode<T>

LinkedListNode<string> node = linkedlstobj.Find(value);

While removing values from Linked List we can remove the node by giving value of the node, removing first element and removing last element.

linkedlstobj.Remove(value);
linkedlstobj.RemoveFirst();
linkedlstobj.RemoveLast();



Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LLEXAMPLE
{
    class Program
    {
        static void Main(string[] args)
        {
            LinkedList<string> linkedlstobj = new LinkedList<string>();
           
            //Adding values into LinkedList in C#          
            linkedlstobj.AddFirst("Ant"); //Add node from begining
            linkedlstobj.AddLast("Fox"); //Add node at last of linked list

            // get linkedListNode by passing value
            LinkedListNode<string> node = linkedlstobj.Find("Fox");
           
            //Adding new value after specific node
            linkedlstobj.AddBefore(node, "Elephant");
            //Adding new value after specific Node
            linkedlstobj.AddAfter(node, "Goat");

            //Removing values into LinkedList in C#
            linkedlstobj.Remove("Fox");//remove by passing value
            linkedlstobj.RemoveFirst();//remove first value in linkedList
            linkedlstobj.RemoveLast();//remove last value in Linkedlist

        }
    }
}