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

    Array ใน C# เป็น Reference Type ต้องใช้ new สร้าง Instance ก่อนจึงจะ Assign ค่าได้ 1. สร้าง Array แล้ว Assign ทีละ Index double[] prices = new double[5]; prices[0] = 3245.50; prices[1] = 1234.50; prices[2] = 8765.50; prices[3] = 5784.50; prices[4] = 6576.50; 2. สร้างและ Initialize พร้อมกัน (Collec

  2. การใช้ Remove, RemoveAt, RemoveRange ใน C# List

    List<T> มีเมธอดลบข้อมูลหลายรูปแบบ ใช้ตามสถานการณ์ เมธอดหลัก MethodคำอธิบายReturnComplexity Remove(T item)ลบ Item แรกที่ Match (Equality)bool (Removed?)O(n) RemoveAt(int index)ลบที่ Index ระบุvoidO(n) RemoveAll(Predicate<T>)ลบทุก Item ที่ Match Conditionint (Count Removed)O(n) Remove

  3. ความแตกต่างระหว่าง Class และ Struct ใน C#

    Class = Reference Type, Struct = Value Type — ความแตกต่างพื้นฐานนี้นำไปสู่พฤติกรรมที่ต่างกันหลายประการ Comparison Table FeatureClass (Reference Type)Struct (Value Type) Memory AllocationHeap (Managed by GC)Stack (หรือ Inline ใน Object อื่น) AssignmentCopy Reference (Shallow)Copy Value (Deep) Nu

  4. final, finally และ finalize ใน C#

    C# ไม่มีคีย์เวิร์ด final เหมือน Java — ใช้คีย์เวิร์ดอื่นแทนตามบริบท 1. final (Java) → sealed (C#) ใช้ sealed เพื่อห้าม Override Method หรือ ห้าม Inherit Class Sealed Method class Base { public virtual void Display() { Console.WriteLine(Base); } } class Derived : Base { public sealed overr

  5. ความแตกต่างระหว่าง Dictionary และ Array ใน C#

    Dictionary<TKey, TValue> และ Array มีโครงสร้างและการใช้งานต่างกันพื้นฐาน Dictionary<TKey, TValue> Key-Value Pair Collection (Hash Table) Key ต้อง Unique, ไม่เป็น Null (Reference Type) Lookup O(1) ด้วย Key Dynamic Size Namespace: System.Collections.Generic การประกาศและใช้งาน using Sys

  6. String Class ใน C#

    string (Alias ของ System.String) เป็น Immutable Reference Type** — ค่าไม่เปลี่ยนแปลงได้หลังสร้าง ทุก Operation ที่ เปลี่ยน สตริง จะสร้าง Instance ใหม่ Properties Propertyคำอธิบาย Lengthจำนวน Char (UTF-16 Code Units) Chars[int index]Indexer — เข้าถึง Char ตำแหน่ง index (Read-only) Methods สำค

  7. Streams และ Byte Streams ใน C#

    Stream เป็น Abstract Base Class แทน Sequence of Bytes — รองรับ Read/Write/Seek แบบ Sequential หรือ Random Access Stream Hierarchy Stream (Abstract) ├── FileStream // ไฟล์บน Disk ├── MemoryStream // Byte Array ใน Memory ├── BufferedStream // Wrapper เพิ่ม Buffering ├── NetworkSt

  8. Serialization และ Deserialization ใน C#

    Serialization = แปลง Object → Byte Stream (เพื่อบันทึก File, Database, ส่ง Network) Deserialization = แปลง Byte Stream → Object (กลับมาใช้งาน) ประเภทหลักใน .NET 1. Binary Serialization (Legacy — ไม่แนะนำ) Serialize ทุก Field (รวม private, readonly) Binary Format — ไม่ Human-readable Versioning ยา

  9. String Format สำหรับ DateTime ใน C#

    ใช้ String.Format หรือ String Interpolation (C# 6+) กับ Standard / Custom Format Specifiers เพื่อจัดรูปแบบ DateTime Standard Format Specifiers Specifierชื่อตัวอย่าง (en-US) dShort Date2/8/2018 DLong DateThursday, February 8, 2018 fFull Date/Time (Short Time)Thursday, February 8, 2018 12:07 PM F

  10. การกลับลำดับคำในสตริง (Reverse Words) ใน C#

    มี 2 ระดับการ Reverse: กลับตัวอักษร (Character Reverse) และ กลับลำดับคำ (Word Reverse) 1. กลับตัวอักษร (Character Reverse) string str = Welcome; // ผลลัพธ์: emocleW // วิธีต่างๆ var r1 = new string(str.Reverse().ToArray()); // LINQ var r2 = new string(str.ToCharArray().Reverse().ToArray(

  11. Regular Expression (Regex) ใน C# พร้อมตัวอย่าง

    Regular Expression (Regex) คือ Pattern สำหรับ Match/Search/Replace ข้อความ .NET มี Regex Engine ใน System.Text.RegularExpressions คลาสหลัก Regex — Static/Instance Methods สำหรับ Match, Replace, Split Match — ผลลัพธ์การ Match ครั้งเดียว MatchCollection — หลาย Match Group / Capture — กลุ่มย่อยใน Pat

  12. แทรกช่องว่างระหว่างคำที่ขึ้นต้นด้วยตัวพิมพ์ใหญ่ใน C#

    ปัญหา: สตริงแบบ PascalCase/CamelCase เช่น WelcomeToMyWebsite ต้องการแปลงเป็น Welcome To My Website วิธีที่ 1: LINQ (กระชับ) char.IsUpper(c) ? + c : c.ToString())).TrimStart(); // ผลลัพธ์: Welcome To My Website วิธีที่ 2: Regex (ทรงพลังกว่า) using System.Text.RegularExpressions; string str = We

  13. การสร้าง HashSet ใน C# (Initializing HashSet)

    HashSet<T> เป็น Collection ที่เก็บค่า ไม่ซ้ำกัน (Unique) และมี Performance O(1) สำหรับ Lookup/Add/Remove ใช้ System.Collections.Generic การสร้างและ Initialize 1. ว่าง แล้ว Add ทีละตัว var set = new HashSet(); set.Add(electronics); set.Add(accessories); set.Add(electronics); // Duplicate — จะ

  14. การเพิ่ม Item เข้า ArrayList ใน C#

    ArrayList เป็น Non-generic Collection ใน System.Collections ปรับขนาดได้อัตโนมัติ (Dynamic Resize) แต่ ไม่แนะนำสำหรับโค้ดใหม่ — ควรใช้ List<T> แทน เหตุผลไม่ควรใช้ ArrayList ❌ Boxing/Unboxing: เก็บ object → Value Types (int, struct) ถูก Box ทุกครั้ง ❌ No Type Safety: ใส่ได้ทุก Type — Error พบไ

  15. Overloaded Method และ Ambiguity (ความคลุมเครือ) ใน C#

    Method Overloading อนุญาตให้มีเมธอดชื่อเดียวกันหลายตัว ต่างกันใน Signature (พารามิเตอร์) แต่ Optional Parameters อาจทำให้เกิด Ambiguity (ความคลุมเครือ) ตอน Compile Time ตัวอย่างที่ทำงานได้ (No Ambiguity) class Student { // Optional Parameter: marks2 = 95 static void DisplayMarks(int marks1,

  16. Mutation Testing ใน C# (ซ้ำกับ 1004092436)

    บทความนี้ซ้ำกับ ID 1004092436 (Mutation Test tools in C#) เนื้อหาเกือบเหมือนกันทุกประการ สรุปสำคัญ (จากบทความก่อนหน้า) Mutation Testing: วัดคุณภาพ Test Suite โดยสร้าง Mutants (โค้ดที่เปลี่ยนเล็กน้อย) แล้วดูว่า Test จับได้หรือไม่ VisualMutator / VisualMutant: Tool ยอดนิยมสำหรับ .NET ผสาน Visual Stu

  17. การพิมพ์ด้วย Font ตัวเองใน C# (Custom Font Printing)

    ใน WinForms/WPF ใช้ System.Drawing (GDI+) หรือ System.Windows.Media สำหรับ Custom Font Printing WinForms (System.Drawing) สร้าง Font using System.Drawing; using System.Drawing.Printing; // FontFamily: ชื่อ Font (ต้องติดตั้งในระบบ) FontFamily fontFamily = new FontFamily(Arial); // Font: ขนาด Styl

  18. การแสดงผลตัวแปร Single และ Multiple ใน C#

    ใช้ Console.WriteLine() แสดงผล ตัวแปรเดียวหรือหลายตัวได้หลายรูปแบบ 1. ตัวแปรเดี่ยว (Single Variable) int a = 10; Console.WriteLine(Value: + a); // String Concatenation Console.WriteLine(Value: {0}, a); // Composite Formatting Console.WriteLine($Value: {a}); // String Interpolati

Total 2668 -คอมพิวเตอร์  FirstPage PreviousPage NextPage LastPage CurrentPage:28/134  20-คอมพิวเตอร์/Page Goto:1 22 23 24 25 26 27 28 29 30 31 32 33 34