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

    ใน C# ทุกอ็อบเจ็กต์มีเมธอด GetHashCode() ที่คืนค่า hash code เป็นจำนวนเต็ม (int) สำหรับสตริง สองสตริงที่มีค่าเท่ากันจะมี hash code เท่ากันเสมอ (แต่ hash code เท่ากันไม่ได้รับประกันว่าสตริงจะเท่ากัน เพราะอาจเกิด collision) ตัวอย่างโค้ด using System; public class Demo { public static void Main(s

  2. การได้ Enumerator สำหรับวนลูปผ่าน HashSet ใน C#

    ใน C# คุณสามารถได้รับ Enumerator เพื่อวนลูปผ่านสมาชิกของ HashSet<T> ได้สองวิธีหลัก ได้แก่การใช้ foreach (ซึ่งใช้ Enumerator ภายในโดยอัตโนมัติ) หรือเรียก GetEnumerator() โดยตรงเพื่อควบคุมการวนลูปได้ละเอียดขึ้น ตัวอย่างโค้ด using System; using System.Collections.Generic; public class Demo {

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

    ใน C# คุณสามารถตรวจสอบว่า ListDictionary มีคีย์ (key) ที่ระบุอยู่หรือไม่ได้โดยใช้เมธอด Contains(key) ซึ่งจะคืนค่า true หากพบคีย์นั้นๆ หรือ false หากไม่พบ ตัวอย่างโค้ด using System; using System.Collections; using System.Collections.Specialized; public class Demo { public static void Main()

  4. ตรวจสอบว่า ListDictionary มีขนาดคงที่หรือไม่ใน C#

    ใน C# คุณสามารถตรวจสอบว่า ListDictionary มีขนาดคงที่ (fixed size) ได้โดยใช้ property IsFixedSize ซึ่งจะคืนค่า true หากขนาดถูกกำหนดไว้ล่วงหน้าและไม่สามารถเปลี่ยนแปลงได้ หรือ false หากสามารถเพิ่ม/ลบข้อมูลได้อย่างอิสระ ตัวอย่างโค้ด using System; using System.Collections; using System.Collections.Speci

  5. ตรวจสอบว่า SortedList ถูกซิงโครไนซ์หรือไม่ใน C#

    ภาพรวม เมธอด static SortedList.Synchronized(SortedList) สร้าง synchronized wrapper สำหรับ SortedList คุณสมบัติ IsSynchronized บอกว่าเป็น wrapper หรือไม่ ตัวอย่างที่ 1: สร้าง Synchronized Wrapper using System; using System.Collections; public class Demo { public static void Main() {

  6. ตรวจสอบว่า StringDictionary ถูกซิงโครไนซ์หรือไม่ใน C#

    ภาพรวม StringDictionary.IsSynchronized เสมอคืนค่า false เพราะ StringDictionary ไม่มี synchronized wrapper ในตัว (ไม่มีเมธอด Synchronized static) ต้องจัดการ thread-safety เอง ตัวอย่างที่ 1: ตรวจสอบ StringDictionary สองตัว using System; using System.Collections; using System.Collections.Specialized;

  7. ตรวจสอบว่า ArrayList ถูกซิงโครไนซ์ (Thread-Safe) หรือไม่ใน C#

    ภาพรวม คุณสมบัติ ArrayList.IsSynchronized บอกว่า ArrayList เป็น synchronized wrapper (thread-safe) หรือไม่ ArrayList ธรรมดาคืนค่า false wrapper จาก ArrayList.Synchronized() คืนค่า true ตัวอย่างที่ 1: ArrayList ธรรมดาสองตัว (ไม่ synchronized) using System; using System.Collections; public class Dem

  8. ตรวจสอบว่า ArrayList มีขนาดคงที่ (Fixed Size) หรือไม่ใน C#

    ภาพรวม คุณสมบัติ ArrayList.IsFixedSize บอกว่า ArrayList มีขนาดคงที่หรือไม่ ArrayList ธรรมดาเป็น false (ขยายได้) แต่ wrapper จาก ArrayList.FixedSize() จะเป็น true ตัวอย่างที่ 1: Synchronized Wrapper (ไม่ใช่ Fixed Size) using System; using System.Collections; public class Demo { public static vo

  9. สร้าง Wrapper ซิงโครไนซ์สำหรับ ArrayList ใน C#

    ภาพรวม เมธอด static ArrayList.Synchronized(ArrayList) คืนค่า wrapper ที่เป็น thread-safe สำหรับ ArrayList ที่ส่งเข้า ให้การเข้าถึงจากหลายเธรดได้ปลอดภัย ตัวอย่างที่ 1: ArrayList ธรรมดา (ไม่ synchronized) using System; using System.Collections; public class Demo { public static void Main() {

  10. สร้าง Wrapper ซิงโครไนซ์สำหรับ Hashtable ใน C#

    ภาพรวม เมธอด static Hashtable.Synchronized(Hashtable) คืนค่า wrapper ที่เป็น thread-safe (synchronized) สำหรับ Hashtable ที่ส่งเข้า ใช้สำหรับการเข้าถึงจากหลายเธรด ตัวอย่างที่ 1: Hashtable ธรรมดา (ไม่ synchronized) using System; using System.Collections; public class Demo { public static void M

  11. สร้าง ArrayList ด้วยความจุเริ่มต้นที่ระบุใน C#

    ภาพรวม คอนสตรัคเตอร์ new ArrayList(int capacity) สร้าง ArrayList พร้อมจัดสรรอาร์เรย์ภายในขนาดที่ระบุล่วงหน้า ช่วยลดการขยายอาร์เรย์ซ้ำเมื่อทราบจำนวนองค์ประกอบประมาณ ตัวอย่างที่ 1: สร้าง ArrayList ความจุ 5 และ 10 using System; using System.Collections; public class Demo { public static void Main

  12. สร้าง HybridDictionary แบบ Case-Sensitive และ Case-Insensitive ใน C#

    ภาพรวม HybridDictionary มีคอนสตรัคเตอร์ new HybridDictionary(bool caseInsensitive) ที่รับพารามิเตอร์บูลีน: true = case-insensitive (ค่าเริ่มต้น), false = case-sensitive ตัวอย่างที่ 1: สร้างแบบ Case-Sensitive (caseInsensitive = false) using System; using System.Collections; using System.Collections.

  13. สร้าง HybridDictionary ว่างพร้อมระบุ Case Sensitivity ใน C#

    ภาพรวม HybridDictionary คอนสตรัคเตอร์เริ่มต้น new HybridDictionary() สร้างดิกชันนารีที่ ไม่คำนึงถึงตัวพิมพ์ใหญ่/เล็กของคีย์ (case-insensitive) โดยใช้ StringComparer.OrdinalIgnoreCase ภายใน ตัวอย่างที่ 1: เพิ่มคีย์ที่ต่างกันแค่ตัวพิมพ์ (D และ e) using System; using System.Collections; using System.C

  14. ตรวจสอบว่า ArrayList เป็น Read-Only หรือไม่ใน C#

    ภาพรวม คุณสมบัติ ArrayList.IsReadOnly เสมอคืนค่า false สำหรับ ArrayList ทั่วไป เพราะ ArrayList อนุญาตให้เพิ่ม ลบ แก้ไขได้เสมอ ยกเว้นกรณีที่ห่อหุ้มด้วย ArrayList.ReadOnly() ตัวอย่างที่ 1: ตรวจสอบ IsReadOnly, IsFixedSize, IsSynchronized using System; using System.Collections; public class Demo {

  15. ดึงค่าที่ดัชนีที่ระบุของ SortedList ใน C#

    ภาพรวม เมธอด SortedList.GetByIndex(int index) คืนค่าที่ดัชนีที่ระบุ (0-based) ตามลำดับที่เรียงของคีย์ ใช้เมื่อต้องการเข้าถึงค่าผ่านตำแหน่งแทนคีย์ ตัวอย่างที่ 1: ดึงค่าที่ดัชนี 2, 5, 6 using System; using System.Collections; public class Demo { public static void Main(String[] args) {

  16. ดึงค่าทั้งหมดใน SortedList ใน C#

    ภาพรวม SortedList.Values คุณสมบัติคืนค่า ICollection ที่มีค่าทั้งหมดเรียงตามลำดับคีย์ คู่กับ Keys ที่คืนคีย์ทั้งหมด ตัวอย่างที่ 1: ดึงค่าและคีย์จาก SortedList แบบ int key, string value using System; using System.Collections; public class Demo { public static void Main(String[] args) {

  17. ตรวจสอบว่า SortedSet และคอลเลกชันที่ระบุมีองค์ประกอบเหมือนกันทั้งหมดหรือไม่ใน C#

    ภาพรวม เมธอด SortedSet<T>.SetEquals(IEnumerable<T>) ตรวจสอบว่าเซตและคอลเลกชันที่ระบุมีองค์ประกอบ เหมือนกันทุกประการ (เซตเท่ากัน) คืนค่า true หากเท่ากัน false หากต่างกัน ตัวอย่างที่ 1: เซตที่ไม่มีค่าเหมือนกัน using System; using System.Collections.Generic; public class Demo { public

  18. ดึง IDictionaryEnumerator จาก OrderedDictionary ใน C#

    ภาพรวม OrderedDictionary.GetEnumerator() คืนค่า IDictionaryEnumerator ใช้วนลูปผ่านคู่คีย์-ค่าในลำดับที่เพิ่ม (insertion order) ต่างจาก Hashtable ที่ไม่รักษาลำดับ ตัวอย่างที่ 1: วนลูป OrderedDictionary ด้วย IDictionaryEnumerator using System; using System.Collections; using System.Collections.Specia

  19. ดึงออบเจ็กต์ที่ด้านบนของ Stack ใน C#

    ภาพรวม Stack<T> ใน namespace System.Collections.Generic เป็นคอลเลกชันแบบ LIFO (Last-In-First-Out) เมธอด Peek() คืนค่าองค์ประกอบที่ด้านบน (top) โดยไม่ลบออก ในขณะที่ Pop() จะลบและคืนค่า ตัวอย่างที่ 1: Peek กับ Stack สตริง using System; using System.Collections.Generic; public class Demo {

  20. ตรวจสอบว่า BitArray เป็น Read-Only หรือไม่ใน C#

    ภาพรวม คุณสมบัติ BitArray.IsReadOnly เสมอคืนค่า false เพราะ BitArray อนุญาตให้แก้ไขบิตได้ตลอดเวลา (ผ่าน Set, SetAll, หรือดัชนี) ไม่มีโหมด read-only ตัวอย่างที่ 1: ตรวจสอบ IsReadOnly และ IsSynchronized using System; using System.Collections; public class Demo { public static void Main() {

Total 2668 -คอมพิวเตอร์  FirstPage PreviousPage NextPage LastPage CurrentPage:109/134  20-คอมพิวเตอร์/Page Goto:1 103 104 105 106 107 108 109 110 111 112 113 114 115