Computer >> Máy Tính >  >> Lập trình >> C#

Phương thức LinkedList AddLast trong C #

Khai báo một mảng chuỗi.

string [] students = {"Jenifer","Angelina","Vera"};

Thêm nó vào LinkedList.

string [] students = {"Jenifer","Angelina","Vera"};

Bây giờ, hãy sử dụng phương thức AddLast () để thêm một nút vào cuối.

list.AddLast("Anne");

Ví dụ

using System;
using System.Collections.Generic;
class Demo {
   static void Main() {
      string [] students = {"Jenifer","Angelina","Vera"};
      LinkedList<string> list = new LinkedList<string>(students);
      foreach (var stu in list) {
         Console.WriteLine(stu);
      }
      // add a node at the end
      Console.WriteLine("Node added at the last...");
      list.AddLast("Anne");
      foreach (var stu in list) {
         Console.WriteLine(stu);
      }
   }
}

Đầu ra

Jenifer
Angelina
Vera
Node added at the last...
Jenifer
Angelina
Vera
Anne