C# Program to create a LinkedList


Firstly, set a string array.

string [] students = {"Tim","Jack","Henry","David","Tom"};

Now, add it to the LinkedList.

LinkedList<string> list = new LinkedList<string>(students);

The above creates a LinkedList and adds node to it.

Let us see the complete example.

Example

 Live Demo

using System;
using System.Collections.Generic;
class Demo {
   static void Main() {
      string [] students = {"Tim","Jack","Henry","David","Tom"};
      LinkedList<string> list = new LinkedList<string>(students);
      foreach (var stu in list) {
         Console.WriteLine(stu);
      }
   }
}

Output

Tim
Jack
Henry
David
Tom

Updated on: 23-Jun-2020

216 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements