亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Inhaltsverzeichnis
Working of LinkedList Class in C#
Constructors of LinkedList Class
Methods of LinkedList Class in C#
Example of LinkedList Class in C#

C# LinkedList

Sep 03, 2024 pm 03:28 PM
c# c# tutorial

A linear data structure for storing the elements in a non-contiguous manner is called a LinkedList in which the pointers are used to link the elements in the linked list with each other and System.Collections.Generic namespace consists of the LinkedList class in C# from which the elements can be removed or can be inserted into in a very quick manner implementing a classic linked list and the allocation of each object is separate in linked list and there is no necessity of copying of entire collection to perform certain operations on the linked list.

Syntax:

The syntax of LinkedList class in C# is as follows:

LinkedList<Type> linkedlist_name = new LinkedList <Type>();

Where Type represents the type of linked list.

Working of LinkedList Class in C#

  • There are nodes present in the linked list and every node consists of two parts namely data field and a link to the node that comes next in the linked list.
  • The type of every node in the linked list is LinkedListNode type.
  • A node can be removed from the linked list and can be inserted back to the same linked list or cab be inserted to another linked list and hence there is no extra allocation on the heap.
  • Inserting the elements into a linked list, removing the elements from the linked list, and obtaining the property of count which is an internal property maintained by the liked list are all O(1) operations.
  • Enumerators are supported by the linked list class as it is a general-purpose linked list.
  • Nothing that makes the linked list inconsistent is supported by the linked list.
  • If the linked list is doubly linked list, then each node has two pointers, one pointing to the previous node in the list and the other one pointing to the next node in the list.

Constructors of LinkedList Class

There are several constructors in the LinkedList class in C#. They are:

  • LinkedList(): A new instance of the linked list class is initialized which is empty.
  • LinkedList(IEnumerable): A new instance of the linked list class is initialized which is taken from the specified implementation of IEnumerable whose capacity is enough to accumulate all the copied elements.
  • LinkedList(SerializationInfo, StreamingContext): A new instance of the linked list class is initialized which can be serialized with the serializationInfo and StreamingContext specified as parameters.

Methods of LinkedList Class in C#

There are several methods in the LinkedList class in C#. They are:

  • AddAfter: A value or new node is added after an already present node in the linked list using the AddAfter method.
  • AddFirst: A value or new node is added at the beginning of the linked list using the AddFirst method.
  • AddBefore: A value or new node is added before an already present node in the linked list using the AddBefore method.
  • AddLast: A value or new node is added at the end of the linked list using the AddLast method.
  • Remove(LinkedListNode): A node specified as a parameter will be removed from the linked list using Remove(LinkedListNode) method.
  • RemoveFirst(): A node at the beginning of the linked list will be removed from the linked list using RemoveFirst() method.
  • Remove(T): The first occurrence of the value specified as a parameter in the linked list will be removed from the linked list using the Remove(T) method.
  • RemoveLast(): A node at the end of the linked list will be removed from the linked list using the RemoveLast() method.
  • Clear(): All the nodes from the linked list will be removed using the Clear() method.
  • Find(T): The value specified as the parameter present in the very first node will be identified by using the Find(T) method.
  • Contains(T): We can use the Contains(T) method to find out if a value is present in the linked list or not.
  • ToString(): A string representing the current object is returned by using the ToString() method.
  • CopyTo(T[], Int32): The whole linked list is copied to an array which is one dimensional and is compatible with the linked list and the linked list begins at the index specified in the array to be copied to using CopyTo(T[], Int32) method.
  • OnDeserialization(Object): After the completion of deserialization, an event of deserialization is raised and the ISerializable interface is implemented using OnDeserialization(Object) method.
  • Equals(Object): If the object specified as the parameter is equal to the current object or not is identified using Equals(Object) method.
  • FindLast(T): The value specified as the parameter present in the last node will be identified by using FindLast(T) method.
  • MemberwiseClone(): A shallow copy of the current object is created using MemeberwiseClone() method.
  • GetEnumerator(): An enumerator is returned using GetEnumerator() method and the returned enumerator loops through the linked list.
  • GetType(): The type of the current instance is returned using GetType() method.
  • GetHashCode(): The GetHashCode() method is the hash function by default.
  • GetObjectData(SerializationInfo, StreamingContext): The data which is necessary to make the linked list serializable is returned by using GetObjectData(SerializationInfo, StreamingContext) method along with implementing the ISerializable interface.

Example of LinkedList Class in C#

C# program to demonstrate AddLast() method, Remove(LinkedListNode) method, Remove(T) method, RemoveFirst() method, RemoveLast() method and Clear() method in Linked List class:

Code:

using System;
using System.Collections.Generic;
//a class called program is defined
public class program
{
// Main Method is called
static public void Main()
{
//a new linked list is created
LinkedList<String> list = new LinkedList<String>();
//AddLast() method is used to add the elements to the newly created linked list
list.AddLast("Karnataka");
list.AddLast("Mumbai");
list.AddLast("Pune");
list.AddLast("Hyderabad");
list.AddLast("Chennai");
list.AddLast("Delhi");
Console.WriteLine("The states in India are:");
//Using foreach loop to display the elements of the newly created linked list
foreach(string places in list)
{
Console.WriteLine(places);
}
Console.WriteLine("The places after using Remove(LinkedListNode) method are:");
//using Remove(LinkedListNode) method to remove a node from the linked list
list.Remove(list.First);
foreach(string place in list)
{
Console.WriteLine(place);
}
Console.WriteLine("The places after using Remove(T) method are:");
//using Remove(T) method to remove a node from the linked list
list.Remove("Chennai");
foreach(string plac in list)
{
Console.WriteLine(plac);
}
Console.WriteLine("The places after using RemoveFirst() method are:");
//using RemoveFirst() method to remove the first node from the linked list
list.RemoveFirst();
foreach(string pla in list)
{
Console.WriteLine(pla);
}
Console.WriteLine("The places after using RemoveLast() method are:");
//using RemoveLast() method to remove the last node from the linked list
list.RemoveLast();
foreach(string pl in list)
{
Console.WriteLine(pl);
}
//using Clear() method to remove all the nodes from the linked list
list.Clear();
Console.WriteLine("The count of places after using Clear() method is: {0}",
list.Count);
}
}

The output of the above program is as shown in the snapshot below:

C# LinkedList

In the above program, a class called program is defined. Then the main method is called. Then a new linked list is created. Then AddLast() method is used to add the elements to the newly created linked list. Then foreach loop is used to display the elements of the newly created linked list. Then Remove(LinkedListNode) method is used to remove a node from the linked list. Then Remove(T) method is used to remove a node from the linked list. Then RemoveFirst() method is used to remove the first node from the linked list. Then RemoveLast() method is used to remove the last node from the linked list. Then Clear() method is used to remove all the nodes from the linked list. The output of the program is shown in the snapshot above.

Das obige ist der detaillierte Inhalt vonC# LinkedList. Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!

Erkl?rung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn

Hei?e KI -Werkzeuge

Undress AI Tool

Undress AI Tool

Ausziehbilder kostenlos

Undresser.AI Undress

Undresser.AI Undress

KI-gestützte App zum Erstellen realistischer Aktfotos

AI Clothes Remover

AI Clothes Remover

Online-KI-Tool zum Entfernen von Kleidung aus Fotos.

Clothoff.io

Clothoff.io

KI-Kleiderentferner

Video Face Swap

Video Face Swap

Tauschen Sie Gesichter in jedem Video mühelos mit unserem v?llig kostenlosen KI-Gesichtstausch-Tool aus!

Hei?e Werkzeuge

Notepad++7.3.1

Notepad++7.3.1

Einfach zu bedienender und kostenloser Code-Editor

SublimeText3 chinesische Version

SublimeText3 chinesische Version

Chinesische Version, sehr einfach zu bedienen

Senden Sie Studio 13.0.1

Senden Sie Studio 13.0.1

Leistungsstarke integrierte PHP-Entwicklungsumgebung

Dreamweaver CS6

Dreamweaver CS6

Visuelle Webentwicklungstools

SublimeText3 Mac-Version

SublimeText3 Mac-Version

Codebearbeitungssoftware auf Gottesniveau (SublimeText3)

Der Unterschied zwischen Multithreading und asynchronem C# Der Unterschied zwischen Multithreading und asynchronem C# Apr 03, 2025 pm 02:57 PM

Der Unterschied zwischen Multithreading und Asynchron besteht darin, dass Multithreading gleichzeitig mehrere Threads ausführt, w?hrend asynchron Operationen ausführt, ohne den aktuellen Thread zu blockieren. Multithreading wird für rechenintensive Aufgaben verwendet, w?hrend asynchron für die Benutzerinteraktion verwendet wird. Der Vorteil des Multi-Threading besteht darin, die Rechenleistung zu verbessern, w?hrend der Vorteil von Asynchron nicht darin besteht, UI-Threads zu blockieren. Die Auswahl von Multithreading oder Asynchron ist von der Art der Aufgabe abh?ngt: Berechnungsintensive Aufgaben verwenden Multithreading, Aufgaben, die mit externen Ressourcen interagieren und die UI-Reaktionsf?higkeit asynchron verwenden müssen.

C# gegen C: Geschichte, Evolution und Zukunftsaussichten C# gegen C: Geschichte, Evolution und Zukunftsaussichten Apr 19, 2025 am 12:07 AM

Die Geschichte und Entwicklung von C# und C sind einzigartig, und auch die Zukunftsaussichten sind unterschiedlich. 1.C wurde 1983 von Bjarnestrustrup erfunden, um eine objektorientierte Programmierung in die C-Sprache einzuführen. Sein Evolutionsprozess umfasst mehrere Standardisierungen, z. B. C 11 Einführung von Auto-Keywords und Lambda-Ausdrücken, C 20 Einführung von Konzepten und Coroutinen und sich in Zukunft auf Leistung und Programme auf Systemebene konzentrieren. 2.C# wurde von Microsoft im Jahr 2000 ver?ffentlicht. Durch die Kombination der Vorteile von C und Java konzentriert sich seine Entwicklung auf Einfachheit und Produktivit?t. Zum Beispiel führte C#2.0 Generics und C#5.0 ein, die eine asynchrone Programmierung eingeführt haben, die sich in Zukunft auf die Produktivit?t und das Cloud -Computing der Entwickler konzentrieren.

So ?ndern Sie das Format von XML So ?ndern Sie das Format von XML Apr 03, 2025 am 08:42 AM

Es gibt verschiedene M?glichkeiten, XML -Formate zu ?ndern: manuell mit einem Texteditor wie Notepad bearbeiten; automatisch Formatierung mit Online- oder Desktop -XML -Formatierungswerkzeugen wie XMLBeautifier; Definieren Sie Conversion -Regeln mithilfe von XML -Conversion -Tools wie XSLT; oder analysieren und mit Verwendung von Programmiersprachen wie Python arbeiten. Seien Sie vorsichtig, wenn Sie die Originaldateien ?ndern und sichern.

Wie man XML in Wort umwandelt Wie man XML in Wort umwandelt Apr 03, 2025 am 08:15 AM

Es gibt drei M?glichkeiten, XML in Wort zu konvertieren: Verwenden Sie Microsoft Word, verwenden Sie einen XML -Konverter oder verwenden Sie eine Programmiersprache.

Wie man XML in JSON umwandelt Wie man XML in JSON umwandelt Apr 03, 2025 am 09:09 AM

Zu den Methoden zum Umwandeln von XML in JSON geh?ren: Schreiben von Skripten oder Programmen in Programmiersprachen (wie Python, Java, C#) zum Konvertieren; Einfügen oder Hochladen von XML -Daten mithilfe von Online -Tools (z. B. XML in JSON, Gojko XML Converter, XML Online -Tools) und Auswahl der JSON -Formatausgabe; Durchführung von Konvertierungsaufgaben mit XML mit JSON -Konvertern (wie Oxygen XML -Editor, Stylus Studio, Altova XMLSPY); Konvertieren von XML in JSON mithilfe von XSLT -Stylesheets; Verwenden von Datenintegrationstools (z. B. informatisch

Was ist C# Multithreading -Programmierung? C# Multithreading -Programmierung verwendet C# Multithreading -Programmierung Was ist C# Multithreading -Programmierung? C# Multithreading -Programmierung verwendet C# Multithreading -Programmierung Apr 03, 2025 pm 02:45 PM

C# Multi-Thread-Programmierung ist eine Technologie, mit der Programme gleichzeitig mehrere Aufgaben ausführen k?nnen. Es kann die Programmeffizienz verbessern, indem es die Leistung verbessert, die Reaktionsf?higkeit verbessert und die parallele Verarbeitung implementiert. W?hrend die Thread -Klasse eine M?glichkeit bietet, Threads direkt zu erstellen, k?nnen erweiterte Tools wie Task und Async/Warted sicherer asynchroner Operationen und eine sauberere Codestruktur liefern. H?ufige Herausforderungen bei der Multithread -Programmierung umfassen Deadlocks, Rassenbedingungen und Ressourcenleckage, die eine sorgf?ltige Gestaltung von Fadenmodellen und die Verwendung geeigneter Synchronisationsmechanismen erfordern, um diese Probleme zu vermeiden.

C# .NET: Erstellen von Anwendungen mit dem .NET -?kosystem C# .NET: Erstellen von Anwendungen mit dem .NET -?kosystem Apr 27, 2025 am 12:12 AM

Wie erstelle ich Anwendungen mit .NET? Erstellen Anwendungen mit .NET k?nnen in den folgenden Schritten erreicht werden: 1) Verstehen Sie die Grundlagen von .NET, einschlie?lich C# Sprache und plattformübergreifender Entwicklungsunterstützung; 2) Kernkonzepte wie Komponenten und Arbeitsprinzipien des .NET -?kosystems lernen; 3) Master Basic und Advanced Nutzung, von einfachen Konsolenanwendungen bis hin zu komplexen Webapis- und Datenbankvorg?ngen; 4) Mit gemeinsamen Fehlern und Debugging -Techniken wie Konfigurations- und Datenbankverbindungsproblemen vertraut sein; 5) Optimierung der Anwendungsleistung und Best Practices wie asynchrone Programmieren und Zwischenspeichern.

Vom Web zum Desktop: Die Vielseitigkeit von C# .NET Vom Web zum Desktop: Die Vielseitigkeit von C# .NET Apr 15, 2025 am 12:07 AM

C#.NETisversatileforbothwebanddesktopdevelopment.1)Forweb,useASP.NETfordynamicapplications.2)Fordesktop,employWindowsFormsorWPFforrichinterfaces.3)UseXamarinforcross-platformdevelopment,enablingcodesharingacrossWindows,macOS,Linux,andmobiledevices.

See all articles