Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> C#
C#
  1. การเข้าถึงอาร์เรย์แบบซิงโครไนซ์ใน C#

    ภาพรวม อาร์เรย์ใน C# มีคุณสมบัติ SyncRoot (มาจาก ICollection) ใช้ร่วมกับ lock เพื่อให้การเข้าถึงอาร์เรย์เป็น thread-safe ตัวอย่างที่ 1: อาร์เรย์จำนวนเต็ม using System; public class Demo { public static void Main() { Array intArr = new int[] { 5, 10, 15, 20, 25, 30, 35, 40 };

  2. คลาส HybridDictionary ใน C#

    ภาพรวม HybridDictionary นำ IDictionary ไปปฏิบัติโดยใช้ ListDictionary เมื่อข้อมูลน้อย และสลับเป็น Hashtable เมื่อข้อมูลเยอะขึ้น อัตโนมัติ เหมาะสำหรับกรณีที่ไม่แน่ใจขนาดคอลเลกชัน คุณสมบัติหลัก ลำดับคุณสมบัติคำอธิบาย 1Countจำนวนคู่คีย์/ค่า 2IsFixedSizeขนาดคงที่หรือไม่

  3. การเข้าถึง HybridDictionary แบบซิงโครไนซ์ใน C#

    ภาพรวม HybridDictionary (ใน System.Collections.Specialized) ใช้ ListDictionary ตอนเล็ก และสลับเป็น Hashtable ตอนใหญ่อัตโนมัติ คุณสมบัติ SyncRoot ใช้สำหรับล็อกการเข้าถึงแบบ thread-safe ตัวอย่างที่ 1: ตรวจสอบคุณสมบัติและล็อก SyncRoot using System; using System.Collections; using System.Collections.Sp

  4. คลาส StringDictionary ใน C#

    ภาพรวม StringDictionary (ใน System.Collections.Specialized) เป็นแฮชเทเบิลที่คีย์และค่าเป็นสตริงอย่างเคร่งครัด (strongly-typed) ใช้งานง่ายกว่า Hashtable สำหรับข้อมูลสตริง คุณสมบัติหลัก ลำดับคุณสมบัติคำอธิบาย 1Countจำนวนคู่คีย์/ค่า 2IsSynchronizedระบุว่า thread-safe หรือไม่

  5. การนับจำนวนสมาชิกทั้งหมดใน List ใน C#

    ภาพรวม คุณสมบัติ List<T>.Count คืนจำนวนสมาชิกใน List ทันที (O(1)) ต่างจาก Count() ของ LINQ ที่ต้องวนลูป ตัวอย่างที่ 1: นับจำนวน แล้วล้างด้วย Clear() using System; using System.Collections.Generic; public class Demo { public static void Main(String[] args) { List<String>

  6. การสร้าง Queue จากคอลเลกชันอื่นใน C#

    ภาพรวม คอนสตรัคเตอร์ Queue<T>(IEnumerable<T> collection) ให้สร้าง Queue ใหม่โดยคัดลอกข้อมูลจากคอลเลกชันอื่น เช่น อาร์เรย์หรือ Queue อื่น ตัวอย่างที่ 1: สร้าง Queue จากอาร์เรย์ของ Queue เดิม using System; using System.Collections.Generic; public class Demo { public static void Main(

  7. การดึงสมาชิกที่ระบุของ Type ปัจจุบันใน C#

    ภาพรวม ใช้ Reflection ผ่าน Type.GetMember(string name) และ Type.GetField(string name) เพื่อดึงข้อมูลสมาชิก (ฟิลด์ เมธอด พร็อพเพอร์ตี ฯลฯ) ของชนิดข้อมูล ตัวอย่างที่ 1: ดึงสมาชิกชื่อ SubName แบบไม่ระบุ BindingFlags using System; using System.Reflection; public class Demo { public static void Mai

  8. การเข้าถึง Stack แบบซิงโครไนซ์ (Thread-safe) ใน C#

    ภาพรวม คลาส Stack (non-generic) มีคุณสมบัติ SyncRoot สำหรับล็อกการเข้าถึงแบบ thread-safe ใช้ร่วมกับคำสั่ง lock ตัวอย่างที่ 1: Stack ของจำนวนเต็ม using System; using System.Collections; public class Demo { public static void Main() { Stack stack = new Stack(); stack.Push(100

  9. การตรวจสอบว่า List มีสมาชิกที่ตรงตามเงื่อนไขใน C#

    ภาพรวม เมธอด List<T>.Exists(Predicate<T>) ใช้ตรวจสอบว่ามีสมาชิกอย่างน้อยหนึ่งตัวที่ทำให้ predicate คืน true หรือไม่ คืนค่า boolean ตัวอย่างที่ 1: ตรวจสอบว่ามีตัวเลขหาร 3 ลงตัวหรือไม่ using System; using System.Collections.Generic; public class Demo { private static bool demo(int i)

  10. การตรวจสอบว่า SortedList มีคีย์เฉพาะหรือไม่ใน C#

    ภาพรวม SortedList จัดเก็บคู่คีย์/ค่าเรียงลำดับตามคีย์ เมธอด Contains(key) ใช้ตรวจสอบว่ามีคีย์นั้นอยู่หรือไม่ คืน true/false ตัวอย่างที่ 1: ตรวจสอบคีย์ C และอัปเดตค่า using System; using System.Collections; public class Demo { public static void Main() { SortedList list = new Sorted

  11. การ lấy Enumerator สำหรับ ArrayList ทั้งหมดใน C#

    ภาพรวม เมธอด GetEnumerator() ของ ArrayList คืน IEnumerator ที่ใช้วนลูปผ่านทุกองค์ประกอบ แบบดั้งเดิมก่อนมี foreach ตัวอย่างที่ 1: ใช้ IEnumerator วนลูป ArrayList หลายตัว using System; using System.Collections; public class Demo { public static void Main(String[] args) { ArrayList li

  12. การหาดัชนีของครั้งแรกที่พบใน StringCollection ใน C#

    ภาพรวม StringCollection (ใน System.Collections.Specialized) ให้เมธอด IndexOf(string) เพื่อคืนดัชนีของครั้งแรกที่พบสตริงที่ระบุ (เริ่มที่ 0) หากไม่พบจะคืน -1 ตัวอย่างที่ 1: ค้นหา Books ใน StringCollection using System; using System.Collections.Specialized; public class Demo { public static void

  13. คลาส ListDictionary ใน C#

    ภาพรวม ListDictionary (อยู่ใน System.Collections.Specialized) ใช้การนำไปปฏิบัติ IDictionary ด้วย singly linked list เหมาะสำหรับคอลเลกชันขนาดเล็ก (น้อยกว่า 10 รายการ) ให้ประสิทธิภาพดีกว่า Hashtable เมื่อข้อมูลน้อย คุณสมบัติหลัก ลำดับคุณสมบัติคำอธิบาย 1Countจำนวนคู่คีย์/ค่า

  14. Queue ใน C# พร้อมตัวอย่างการใช้งาน

    ภาพรวม คลาส Queue<T> ใน C# เป็นคอลเลกชันแบบ First-In-First-Out (FIFO) ใช้สำหรับจัดเก็บวัตถุที่ต้องการประมวลผลตามลำดับที่เพิ่มเข้าไป เมธอดและคุณสมบัติหลัก ลำดับ เมธอด / คุณสมบัติ คำอธิบาย 1Clear()ลบวัตถุทั้งหมดออกจาก

  15. การตั้งค่าบิตที่ตำแหน่งเฉพาะใน BitArray ให้เป็นค่าที่ระบุใน C#

    ภาพรวม คลาส BitArray ในเนมสเปซ System.Collections ให้เมธอด Set(int index, bool value) เพื่อเปลี่ยนค่าบิตที่ตำแหน่งที่กำหนดเป็น true (1) หรือ false (0) นอกจากนี้ยังเข้าถึงผ่านดัชนี arr[index] = value ได้เช่นกัน ตัวอย่างที่ 1: เปลี่ยนบิตที่ตำแหน่ง 2 เป็น false using System; using System.Collections;

  16. การลบ Node ที่ระบุออกจาก LinkedList ใน C#

    โค้ดสำหรับลบ Node ที่ระบุออกจาก LinkedList มีดังนี้: ตัวอย่าง using System; using System.Collections.Generic; public class Demo { public static void Main() { LinkedList<int> list = new LinkedList<int>(); list.AddLast(100); list.AddLast(200); li

  17. SortedList ใน C# พร้อมตัวอย่างและคำอธิบาย

    คลาส SortedList ใน C# แสดงถึงคอลเลกชันของคู่ Key/Value ที่เรียงลำดับตาม Key และเข้าถึงได้ทั้งด้วย Key และ Index ต่อไปนี้คือ Properties ของคลาส SortedList: ลำดับ Property & Description 1 CapacityGet หรือ Set ความจุของ SortedList Object 2 CountGet จำนวน Elements ใน SortedList Object 3

  18. จำนวน Elements ใน HashSet C#

    HashSet<T> - Count Property HashSet<T> (ใน System.Collections.Generic) เป็น Collection ที่เก็บ Unique Values (ไม่ซ้ำ) ใช้ Count Property ดึงจำนวน Elements ตัวอย่างที่ 1: HashSet Basic Operations using System; using System.Collections.Generic; public class Demo { public static void

  19. การค้นหาใน SortedList Object ด้วย C#

    โค้ดสำหรับค้นหาใน SortedList Object มีดังนี้: ตัวอย่าง using System; using System.Collections; public class Demo { public static void Main() { SortedList list = new SortedList(); list.Add(1, One); list.Add(2, Two); list.Add(3, Three); list.Add(4,

Total 2668 -คอมพิวเตอร์  FirstPage PreviousPage NextPage LastPage CurrentPage:119/134  20-คอมพิวเตอร์/Page Goto:1 113 114 115 116 117 118 119 120 121 122 123 124 125