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

    ภาพรวม Mutex (Mutual Exclusion) เป็น Synchronization Primitive ที่ทำงานข้าม Process ได้ (Cross-process) ใช้สำหรับป้องกันการเข้าถึงทรัพยากรร่วมกันระหว่าง Process หลายตัว การสร้าง Mutex using System; using System.Threading; // 1. Unnamed Mutex (Local to Process) Mutex localMutex = new Mutex(); //

  2. ความแตกต่างระหว่าง public, static, void ใน C#

    ภาพรวม คำสำคัญเหล่านี้มักปรากฏร่วมกันใน Main Method ซึ่งเป็น Entry Point ของโปรแกรม C# โครงสร้าง Main Method using System; class Demo { // public static void Main(string[] args) public static void Main(string[] args) { Console.WriteLine("My first program in C#!"); }

  3. เทียบเท่า VB Module ใน C#: Static Class

    ภาพรวม VB.NET Module คล้ายกับ static class ใน C# - สมาชิกทั้งหมดเป็น Static เข้าถึงได้โดยไม่ต้องสร้าง Instance การเปรียบเทียบ VB.NET Module Module MyModule Public Sub Display() MsgBox("Demo!") End Sub Public Property Counter As Integer = 0 End Module ใช้งาน MyModu

  4. Thread-Safe Concurrent Collections ใน C#

    ภาพรวม Namespace System.Collections.Concurrent จัดเตรียมคอลเลกชันที่ Thread-Safe และ Scalable สำหรับ Multi-threaded Applications คอลเลกชันหลัก ClassTypeUse CaseKey Methods ConcurrentDictionary<TKey,TValue>DictionaryThread-safe key-value store, CacheGetOrAdd, AddOrUpdate, TryGetValue, TryR

  5. กลับลำดับ Stack ใน C#

    ภาพรวม Stack<T> เป็น LIFO (Last-In-First-Out) การ Reverse Stack คือการ Pop จาก Stack เดิมแล้ว Push เข้า Stack ใหม่ โค้ดตัวอย่าง using System; using System.Collections.Generic; public class Program { public static void Main() { var stack = new Stack<char>(); stack.P

  6. จัดเรียง String Array ใน C#

    ภาพรวม ใช้ Array.Sort จัดเรียงอาร์เรย์สตริงแบบ In-place (แก้ไขอาร์เรย์ต้นฉบับ) หรือ LINQ OrderBy สร้างอาร์เรย์ใหม่ โค้ดตัวอย่าง using System; using System.Linq; public class Program { public static void Main() { string[] values = { "tim", "amit", "tom", &

  7. คอมไพล์และรัน C# บน macOS: VS Code และ Visual Studio for Mac

    ภาพรวม พัฒนา C# บน macOS ด้วย VS Code (แนะนำ) หรือ Visual Studio for Mac (จะถูก Retire ใน Aug 2024) ติดตั้ง .NET SDK บน macOS Homebrew (แนะนำ) brew install --cask dotnet-sdk # หรือ specific version brew install dotnet@8 Official Installer ดาวน์โหลดจาก dotnet.microsoft.com → macOS Installer (.pkg

  8. คอมไพล์และรัน C# บน Linux: VS Code และ .NET SDK

    ภาพรวม พัฒนา C# บน Linux ได้อย่างเต็มประสิทธิภาพด้วย .NET SDK และ VS Code (MonoDevelop/Xamarin Studio ถูก deprecated แล้ว) ติดตั้ง .NET SDK บน Linux Ubuntu/Debian # Add Microsoft package repository wget https://packages.microsoft.com/config/ubuntu/22.04/packages-microsoft-prod.deb -O packages-mic

  9. คอมไพล์และรัน C# บน Windows: Visual Studio

    ภาพรวม Visual Studio เป็น IDE หลักสำหรับพัฒนา C# บน Windows รองรับ .NET Framework, .NET Core, .NET 5+ พร้อมเครื่องมือครบครัน คุณสมบัติหลักของ Visual Studio IntelliSense: Code completion, parameter info, quick info Debugger: Breakpoints, watch windows, call stack, immediate window Refactoring: Rena

  10. Threads และ Thread Synchronization ใน C#

    ภาพรวม Thread Synchronization ป้องกัน Race Condition เมื่อหลายเธรดเข้าถึง Shared Resource เครื่องมือหลัก: lock, Mutex, Monitor, Semaphore, ReaderWriterLockSlim 1. lock Statement (Monitor) - พื้นฐานที่สุด public class BankAccount { private readonly object _lock = new object(); private decim

  11. ตรวจสอบความถูกต้องของ Password ใน C#

    ภาพรวม สร้าง Password Validator ตรวจสอบเงื่อนไข: ความยาว, ตัวพิมพ์ใหญ่/เล็ก, ตัวเลข, สัญลักษณ์พิเศษ, ไม่มี whitespace โค้ดตัวอย่าง: Password Validator Class using System; using System.Text.RegularExpressions; public class PasswordValidator { public static ValidationResult Validate(string pass

  12. Clone หรือ Copy List ใน C#

    ภาพรวม คัดลอก List ใน C# มีหลายวิธี: Shallow Copy (คัดลอก Reference) และ Deep Copy (คัดลอก Object ใหม่ทั้งหมด) โค้ดตัวอย่าง: Shallow Copy using System; using System.Collections.Generic; using System.Linq; public class Demo { public static void Main() { List<string> original = ne

  13. หาความยาว Jagged Array ด้วย Property Length ใน C#

    ภาพรวม Jagged Array (T[][]) เป็น Array ของ Arrays ใช้ Length หาจำนวนแถว (Rows) และ Rank จะเป็น 1 เสมอ โค้ดตัวอย่าง using System; public class Program { public static void Main() { int[][] jagged = new int[][] { new int[] { 0, 0 }, new int[] { 1, 2 },

  14. ตรวจสอบว่าสอง List มี Element ซ้ำกันหรือไม่ใน C#

    ภาพรวม ใช้ HashSet<T> และ LINQ Intersect หรือ Any เพื่อตรวจสอบว่าสอง Collection มีสมาชิกร่วมกันหรือไม่ โค้ดตัวอย่าง using System; using System.Collections.Generic; using System.Linq; public class Program { public static void Main() { int[] arr1 = { 65, 57, 63, 98 }; int[

  15. ลบ Element ซ้ำออกจาก List ใน C#

    ภาพรวม ใช้ LINQ Distinct() สร้าง List ใหม่ที่ไม่มีค่าซ้ำ รักษาลำดับการปรากฏครั้งแรก โค้ดตัวอย่าง using System; using System.Collections.Generic; using System.Linq; public class Demo { public static void Main() { List<int> list = new List<int> { 50, 90, 50, 100 };

  16. ตรวจสอบว่าค่าใน List ทุกค่ามากกว่าค่าที่กำหนดใน C#

    ภาพรวม ใช้ LINQ All หรือ Where ตรวจสอบว่า element ทุกตัวใน Array/List ตรงตามเงื่อนไขหรือไม่ โค้ดตัวอย่าง 80 var greaterThan = arr.Where(x => x > threshold).ToArray(); Console.WriteLine($"Values > {threshold}: [{string.Join(", ", greaterThan)}]")

  17. แสดงค่า Unique จาก List ใน C#

    ภาพรวม ใช้ LINQ Distinct() เพื่อกรองค่าที่ซ้ำออกจาก List คืนค่า IEnumerable<T> สามารถแปลงกลับเป็น List ได้ด้วย ToList() โค้ดตัวอย่าง using System; using System.Collections.Generic; using System.Linq; public class Demo { public static void Main() { List<int> list = new List

  18. ลบ Item ออกจาก HashSet ใน C#

    ภาพรวม HashSet<T> เป็นคอลเลกชันที่ไม่มีค่าซ้ำ ใช้ Remove หรือ RemoveWhere เพื่อลบข้อมูล โค้ดตัวอย่าง using System; using System.Collections.Generic; public class Program { public static void Main() { var names = new HashSet<string>(); names.Add("Tim");

  19. ลบคำซ้ำออกจากประโยคใน C#

    ภาพรวม ใช้ LINQ Distinct() หลังจากแยกคำด้วย Split เพื่อลบคำซ้ำ พร้อมจัดการ Case Sensitivity โค้ดตัวอย่าง using System; using System.Linq; public class Program { public static void Main() { string sentence = "One Two Three One"; Console.WriteLine($"Original: {sen

  20. แทนที่ Special Character ใน String ด้วย C#

    ภาพรวม ใช้ String.Replace แทนที่อักขระพิเศษ (special characters) ในสตริง เช่น $, #, @, ฯลฯ โค้ดตัวอย่าง using System; public class Program { public static void Main() { string str = "abcd$ef$gh"; Console.WriteLine($"Original: {str}"); // แทนที่ $ ด

Total 2668 -คอมพิวเตอร์  FirstPage PreviousPage NextPage LastPage CurrentPage:37/134  20-คอมพิวเตอร์/Page Goto:1 31 32 33 34 35 36 37 38 39 40 41 42 43