Base de conhecimentoCentro de Exames
PT · PTPortuguês (Portugal)
Escolher idioma13

CKTIS / C#

System.Collections.Generic.LinkedList: referência prática

System.Collections.Generic.LinkedList: referência prática: LinkedList<T> é uma lista duplamente ligada com inserção ou remoção constante quando o nó já é conhecido.

Versão: .NET API; verified on .NET 10.0.14

Sintaxe

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

LinkedList é uma lista duplamente ligada com inserção ou remoção constante quando o nó já é conhecido.

Usa-a quando nós conhecidos são movidos frequentemente e não é necessário acesso aleatório indexado.

Procurar um valor tem custo linear e cada LinkedListNode só pode pertencer a uma lista de cada vez.

First e Last são null numa lista vazia e um nó removido perde a propriedade List.

O programa completo usa realmente System.Collections.Generic.LinkedList; o stdout exato esperado é 2,3.

Exemplos

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}");

Resultado

2,3

O programa completo usa realmente `System.Collections.Generic.LinkedList`; o stdout exato esperado é `2,3`.

Fontes