Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C#

System.Collections.Generic.LinkedList: practical reference

System.Collections.Generic.LinkedList: practical reference: LinkedList<T> is a doubly linked list with constant-time insertion or removal when the node is already known.

Version: .NET API; verified on .NET 10.0.14

Syntax

System.Collections.Generic.LinkedList /* select a documented member or constructor */

LinkedList is a doubly linked list with constant-time insertion or removal when the node is already known.

Use it when known nodes move frequently and indexed random access is not required.

Finding a value is linear time, and each LinkedListNode can belong to only one list at a time.

First and Last are null for an empty list, and a removed node has its List property cleared.

The complete program actually uses System.Collections.Generic.LinkedList; its exact expected stdout is 2,3.

Examples

using System;
using System.Buffers;
using System.Collections.Concurrent;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
using Number = System.Int32;

var list = new LinkedList<int>();
list.AddFirst(2);
list.AddLast(3);
Console.WriteLine($"{list.First!.Value},{list.Last!.Value}");

Result

2,3

The complete program actually uses `System.Collections.Generic.LinkedList`; its exact expected stdout is `2,3`.

Sources