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

    ภาพรวม เมธอด GetTypeCode() คืนค่า TypeCode แสดงรหัสประเภทของค่าที่เป็น Int32 (int) ซึ่งเป็นค่าคงที่ TypeCode.Int32 ตัวอย่าง 1: ค่า int ทั่วไป using System; public class Demo { public static void Main() { int val1 = 100; int val2 = 50; Console.WriteLine(Value1 = + val1)

  2. การตรวจสอบว่าอินสแตนซ์ UInt64 เท่ากับออบเจ็กต์หรือค่า UInt64 อื่นใน C#

    ภาพรวม เมธอด Equals() ของ UInt64 ใช้เปรียบเทียบว่าอินสแตนซ์มีค่าเท่ากับออบเจ็กต์หรือค่า UInt64 อื่นหรือไม่ คืนค่า bool ตัวอย่าง 1: ค่าไม่เท่ากัน using System; public class Demo { public static void Main() { ulong val1 = 44565777; ulong val2 = 77878787; bool res = val1.E

  3. การรับรหัสแฮชของอินสแตนซ์ UInt64 ปัจจุบันใน C#

    ภาพรวม เมธอด GetHashCode() ของโครงสร้าง UInt64 (ulong) คืนค่ารหัสแฮช 32 บิตที่ใช้สำหรับอัลกอริทึมแฮชตารางและการเปรียบเทียบความเท่าเทียม ตัวอย่าง 1: ค่าปกติและค่าต่ำสุด using System; public class Demo { public static void Main() { ulong val1 = 8768768; ulong val2 = UInt64.MinVal

  4. คีย์เวิร์ด finally ใน C#

    ภาพรวม คีย์เวิร์ด finally ใช้สร้างบล็อกโค้ดที่จะทำงาน เสมอ ไม่ว่าจะมีข้อยกเว้นเกิดขึ้นหรือไม่ กรณีทั่วไปคือการปิดไฟล์ ปล่อยทรัพยากร หรือทำความสะอาด ไวยากรณ์ try { // โค้ดที่อาจโยนข้อยกเว้น } catch (ExceptionName e1) { // จัดการข้อยกเว้นชนิดที่ 1 } catch (ExceptionName e2) { // จัดการข้อ

  5. โครงสร้าง Byte ใน C#

    ภาพรวม Byte ใน C# เป็นโครงสร้าง (struct) ที่แทนจำนวนเต็มไม่มีเครื่องหมาย 8 บิต (ค่า 0 ถึง 255) มีฟิลด์และเมธอดที่มีประโยชน์หลายอย่าง ฟิลด์สำคัญ ลำดับฟิลด์และคำอธิบาย 1MaxValueค่าสูงสุดที่ Byte เก็บได้ (255) – ค่าคงที่ 2MinValueค่าต่ำสุดที่ Byte เก็บได้ (0) – ค่าคงที่ เมธอดหลัก ลำดับเมธอดแล

  6. การตั้งค่าบิตทั้งหมดใน BitArray ให้เป็นค่าที่ระบุใน C#

    ภาพรวม คลาส BitArray ใน namespace System.Collections ให้เมธอด SetAll(Boolean) เพื่อตั้งค่าบิตทุกตัวในอาร์เรย์ให้เป็น true หรือ false พร้อมกัน บทความนี้แสดงตัวอย่างการใช้งาน ตัวอย่าง 1: ตั้งค่าบิตทั้งหมดเป็น true using System; using System.Collections; public class Demo { public static void Mai

  7. การกลับลำดับสมาชิกใน ArrayList ทั้งหมดหรือในช่วงที่ระบุใน C#

    ภาพรวม ใน C# คลาส ArrayList มีเมธอด Reverse() สำหรับกลับลำดับสมาชิกทั้งหมด และ Reverse(Int32, Int32) สำหรับกลับลำดับในช่วงที่กำหนด (เริ่มจากดัชนีและจำนวนสมาชิก) บทความนี้จะสาธิตทั้งสองกรณีพร้อมโค้ดตัวอย่างและผลลัพธ์ ตัวอย่าง 1: กลับลำดับ ArrayList ทั้งหมด using System; using System.Collections; pu

  8. Stack ใน C# พร้อมตัวอย่าง

    ภาพรวม Stack (non-generic) และ Stack<T> แทนคอลเลกชัน LIFO (Last-In-First-Out) ใช้สำหรับการย้อนกลับ (undo), การประเมินนิพจน์, การค้นหาแบบ depth-first ฯลฯ คุณสมบัติหลัก ลำดับคุณสมบัติคำอธิบาย 1Countจำนวนสมาชิก 2IsSynchronizedthread-safe หรือไม่ 3SyncRootออบเจ็ก

  9. การกลับลำดับสมาชิกใน List ทั้งหมดหรือช่วงที่ระบุใน C#

    ภาพรวม เมธอด List<T>.Reverse() กลับลำดับสมาชิกทั้งหมด และ Reverse(int index, int count) กลับเฉพาะช่วง ตัวอย่างที่ 1: กลับลำดับ 4 สมาชิกเริ่มจากดัชนี 2 Three, Four, Five, Six Console.WriteLine(Elements in ArrayList2...Reversed 4 elements beginning from index 2); foreach (stri

  10. พารามิเตอร์ของเมธอดใน C#

    ภาพรวม พารามิเตอร์ใช้ส่งข้อมูลเข้าและรับข้อมูลกลับจากเมธอด ประกอบไปด้วย: Access Specifier - ความมองเห็น (public, private, protected, internal) Return type - ชนิดข้อมูลที่คืน (void หากไม่คืนค่า) Method name - ชื่อเมธอด (unique, case-sensitive) Parameter list - รายการพารามิเตอร์ในวงเล

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

    ภาพรวม เมธอด Dictionary<TKey, TValue>.ContainsValue(TValue) ตรวจสอบว่ามีค่า (value) ที่ระบุอยู่ในพจนานุกรมหรือไม่ คืน boolean ตัวอย่างที่ 1: พบค่า Kevin using System; using System.Collections.Generic; public class Demo { public static void Main() { Dictionary<string, strin

  12. การดึง TypeCode ของชนิดค่า UInt64 ใน C#

    ภาพรวม โครงสร้าง UInt64 (unsigned 64-bit integer) มีเมธอด GetTypeCode() คืน TypeCode.UInt64 ตัวอย่างที่ 1: ค่า 55 และ 100 using System; public class Demo { public static void Main() { ulong val1 = 55; ulong val2 = 100; TypeCode type1 = val1.GetTypeCode(); T

  13. การดึงอินเทอร์เฟซเฉพาะที่ Type ปัจจุบันนำมาหรือสืบทอดใน C#

    ภาพรวม เมธอด Type.GetInterface(string name, bool ignoreCase) คืน Type ของอินเทอร์เฟซที่มีชื่อตรงตามที่ระบุ (คืน null หากไม่พบ) ตัวอย่างที่ 1: หา IFormattable ของ double using System; public class Demo { public static void Main() { Type type = typeof(double); Type myInterfac

  14. การดึงอินเทอร์เฟซทั้งหมดที่ Type ปัจจุบันนำมาหรือสืบทอดใน C#

    ภาพรวม เมธอด Type.GetInterfaces() คืนอาร์เรย์ Type[] ของอินเทอร์เฟซทั้งหมดที่ชนิดข้อมูลนำมาใช้ (implement) หรือสืบทอด (inherit) รวมถึงของ base class ตัวอย่างที่ 1: ชนิด float using System; public class Demo { public static void Main() { Type type = typeof(float); Type myInt

  15. การดึง TypeCode ของชนิดค่า UInt32 ใน C#

    ภาพรวม โครงสร้าง UInt32 (unsigned 32-bit integer) มีเมธอด GetTypeCode() คืน TypeCode.UInt32 ตัวอย่างที่ 1: ค่า 55 และ 100 using System; public class Demo { public static void Main() { uint val1 = 55; uint val2 = 100; TypeCode type1 = val1.GetTypeCode(); Typ

  16. การแทรกสมาชิกเข้า ArrayList ที่ดัชนีที่ระบุใน C#

    ภาพรวม เมธอด ArrayList.Insert(int index, object value) แทรกสมาชิกที่ดัชนีที่กำหนด (0-based) ขยับสมาชิกเดิมไปท้าย ตัวอย่างที่ 1: แทรก Twelve ที่ดัชนี 4 using System; using System.Collections; public class Demo { public static void Main() { ArrayList list = new ArrayList(); l

  17. การแทรกออบเจ็กต์ไปที่ด้านบนของ Stack ใน C#

    ภาพรวม เมธอด Stack<T>.Push(T item) ใส่ออบเจ็กต์ไว้ที่ด้านบน (top) ของสแต็ก ทำงานแบบ LIFO (Last-In-First-Out) ตัวอย่างที่ 1: Stack ของจำนวนเต็ม using System; using System.Collections.Generic; public class Demo { public static void Main() { Stack<int> stack = new Stack<

  18. การนับจำนวนคู่คีย์/ค่าใน Hashtable ใน C#

    ภาพรวม คุณสมบัติ Hashtable.Count คืนจำนวนคู่คีย์/ค่าที่จัดเก็บอยู่ (O(1)) ตัวอย่างที่ 1: เพิ่มข้อมูลและนับ using System; using System.Collections; public class Demo { public static void Main() { Hashtable hash = new Hashtable(); hash.Add(A, SUV); hash.Add(B, MUV);

  19. การดึงสมาชิกทั้งหมดของ Type ปัจจุบันใน C#

    ภาพรวม เมธอด Type.GetMembers() คืนอาร์เรย์ MemberInfo[] ของสมาชิกทั้งหมด (public instance โดยค่าเริ่มต้น) รวมถึงเมธอด ฟิลด์ พร็อพเพอร์ตี イベント คอนสตรัคเตอร์ ฯลฯ ตัวอย่างที่ 1: GetMembers() โดยไม่ระบุ BindingFlags using System; using System.Reflection; public class Demo { public static void Main

  20. การดึง TypeCode ของชนิดค่า Int16 ใน C#

    ภาพรวม โครงสร้าง Int16 (signed 16-bit integer) มีเมธอด GetTypeCode() คืนค่า TypeCode.Int16 ระบุชนิดข้อมูลอย่างชัดเจน ตัวอย่างที่ 1: ค่า 0 และ Int16.MaxValue using System; public class Demo { public static void Main() { short val1 = 0; short val2 = Int16.MaxValue; // 32767

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