国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

目錄
C# 中 LinkedList 類別的工作
LinkedList 類別的建構(gòu)子
C#中LinkedList類別的方法
Example of LinkedList Class in C#

C# 鍊錶

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

以非連續(xù)方式儲存元素的線性資料結(jié)構(gòu)稱為 LinkedList,其中指標(biāo)用於將鍊錶中的元素相互鏈接,System.Collections.Generic 命名空間由 LinkedList C# 中的類,可以以非??焖俚姆绞綇闹袆h除或插入元素,實現(xiàn)經(jīng)典鍊錶,並且每個對象的分配在鍊錶中是單獨的,並且無需複製整個集合來執(zhí)行某些操作在鏈接列表上。

文法:

C#中LinkedList類別的語法如下:

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

其中Type代表鍊錶的型別。

C# 中 LinkedList 類別的工作

  • 鍊錶中存在節(jié)點,每個節(jié)點由兩個部分組成,即資料欄位和指向鍊錶中下一個節(jié)點的連結(jié)。
  • 鍊錶中每個節(jié)點的型別都是LinkedListNode;型別。
  • 節(jié)點可以從鍊錶中刪除,也可以插入回同一個鍊錶,也可以插入到另一個鍊錶,因此堆上沒有額外的分配。
  • 向鍊錶中插入元素、從鍊錶中刪除元素、取得按讚清單維護(hù)的內(nèi)部屬性count屬性都是O(1)操作。
  • 鍊錶類別支援枚舉器,因為它是通用鍊錶。
  • 鍊錶不支援任何使鍊錶不一致的東西。
  • 如果鍊錶是雙向鍊錶,那麼每個節(jié)點都有兩個指針,一個指向鍊錶中的前一個節(jié)點,另一個指向鍊錶中的下一個節(jié)點。

LinkedList 類別的建構(gòu)子

C#中的LinkedList類別中有幾個建構(gòu)子。他們是:

  • LinkedList(): 鍊錶類別的新實例被初始化,該實例為空。
  • LinkedList(IEnumerable):初始化鍊錶類別的新實例,該實例取自 IEnumerable 的指定實現(xiàn),其容量足以累積所有複製的元素。
  • LinkedList(SerializationInfo, StreamingContext): 鍊錶類別的新實例被初始化,可以使用指定為參數(shù)的serializationInfo和StreamingContext進(jìn)行序列化。

C#中LinkedList類別的方法

C#中的LinkedList類別中有幾個方法。他們是:

  • 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# 鍊錶

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.

以上是C# 鍊錶的詳細(xì)內(nèi)容。更多資訊請關(guān)注PHP中文網(wǎng)其他相關(guān)文章!

本網(wǎng)站聲明
本文內(nèi)容由網(wǎng)友自願投稿,版權(quán)歸原作者所有。本站不承擔(dān)相應(yīng)的法律責(zé)任。如發(fā)現(xiàn)涉嫌抄襲或侵權(quán)的內(nèi)容,請聯(lián)絡(luò)admin@php.cn

熱AI工具

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅(qū)動的應(yīng)用程序,用於創(chuàng)建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發(fā)環(huán)境

Dreamweaver CS6

Dreamweaver CS6

視覺化網(wǎng)頁開發(fā)工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

C# 中的隨機數(shù)產(chǎn)生器 C# 中的隨機數(shù)產(chǎn)生器 Sep 03, 2024 pm 03:34 PM

C# 隨機數(shù)產(chǎn)生器指南。在這裡,我們討論隨機數(shù)產(chǎn)生器的工作原理、偽隨機數(shù)和安全數(shù)的概念。

c#多線程和異步的區(qū)別 c#多線程和異步的區(qū)別 Apr 03, 2025 pm 02:57 PM

多線程和異步的區(qū)別在於,多線程同時執(zhí)行多個線程,而異步在不阻塞當(dāng)前線程的情況下執(zhí)行操作。多線程用於計算密集型任務(wù),而異步用於用戶交互操作。多線程的優(yōu)勢是提高計算性能,異步的優(yōu)勢是不阻塞 UI 線程。選擇多線程還是異步取決於任務(wù)性質(zhì):計算密集型任務(wù)使用多線程,與外部資源交互且需要保持 UI 響應(yīng)的任務(wù)使用異步。

C#與C:歷史,進(jìn)化和未來前景 C#與C:歷史,進(jìn)化和未來前景 Apr 19, 2025 am 12:07 AM

C#和C 的歷史與演變各有特色,未來前景也不同。 1.C 由BjarneStroustrup在1983年發(fā)明,旨在將面向?qū)ο缶幊桃隒語言,其演變歷程包括多次標(biāo)準(zhǔn)化,如C 11引入auto關(guān)鍵字和lambda表達(dá)式,C 20引入概念和協(xié)程,未來將專注於性能和系統(tǒng)級編程。 2.C#由微軟在2000年發(fā)布,結(jié)合C 和Java的優(yōu)點,其演變注重簡潔性和生產(chǎn)力,如C#2.0引入泛型,C#5.0引入異步編程,未來將專注於開發(fā)者的生產(chǎn)力和雲(yún)計算。

C# 中的質(zhì)數(shù) C# 中的質(zhì)數(shù) Sep 03, 2024 pm 03:35 PM

C# 質(zhì)數(shù)指南。這裡我們討論c#中素數(shù)的介紹和範(fàn)例以及程式碼實作。

xml怎麼改格式 xml怎麼改格式 Apr 03, 2025 am 08:42 AM

可以採用多種方法修改 XML 格式:使用文本編輯器(如 Notepad )進(jìn)行手工編輯;使用在線或桌面 XML 格式化工具(如 XMLbeautifier)進(jìn)行自動格式化;使用 XML 轉(zhuǎn)換工具(如 XSLT)定義轉(zhuǎn)換規(guī)則;或者使用編程語言(如 Python)進(jìn)行解析和操作。修改時需謹(jǐn)慎,並備份原始文件。

c#多線程編程是什麼  c#多線程編程用處 c#多線程編程是什麼 c#多線程編程用處 Apr 03, 2025 pm 02:45 PM

C# 多線程編程是一種讓程序同時執(zhí)行多項任務(wù)的技術(shù),它可以通過提升性能、提高響應(yīng)能力和實現(xiàn)並行處理來提高程序效率。雖然 Thread 類提供了直接創(chuàng)建線程的方法,但 Task 和 async/await 等高級工具可以提供更安全的異步操作和更簡潔的代碼結(jié)構(gòu)。多線程編程中常見的難題包括死鎖、競態(tài)條件和資源洩漏,需要仔細(xì)設(shè)計線程模型和使用適當(dāng)?shù)耐綑C制來避免這些問題。

xml怎麼轉(zhuǎn)換成json xml怎麼轉(zhuǎn)換成json Apr 03, 2025 am 09:09 AM

將 XML 轉(zhuǎn)換為 JSON 的方法包括:使用編程語言(如 Python、Java、C#)編寫腳本或程序進(jìn)行轉(zhuǎn)換;使用在線工具(如 XML 轉(zhuǎn)換為 JSON、Gojko's XML 轉(zhuǎn)換器、XML 在線工具)粘貼或上傳 XML 數(shù)據(jù)並選擇 JSON 格式輸出;使用 XML 到 JSON 轉(zhuǎn)換器(如 Oxygen XML Editor、Stylus Studio、Altova XMLSpy)執(zhí)行轉(zhuǎn)換任務(wù);使用 XSLT 樣式表將 XML 轉(zhuǎn)換為 JSON;使用數(shù)據(jù)集成工具(如 Informatic

xml如何轉(zhuǎn)化為word xml如何轉(zhuǎn)化為word Apr 03, 2025 am 08:15 AM

有三種將 XML 轉(zhuǎn)換為 Word 的方法:使用 Microsoft Word、使用 XML 轉(zhuǎn)換器或使用編程語言。

See all articles