Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> C#
C#
  1. Pre-processor Directive ใน C# คืออะไร

    C# Compiler ไม่มี Preprocessor แยกต่างหาก แต่ Directives จะถูกประมวลผลเหมือนมีอยู่ Preprocessor Directives ใช้ช่วยใน Conditional Compilation (การคอมไพล์แบบมีเงื่อนไข) Preprocessor Directives ให้คำสั่งกับ Compiler ให้ประมวลผลข้อมูลก่อนการคอมไพล์จริง รายการ Preprocessor Directives ใน C# ลำดับDirecti

  2. User-defined Exceptions ใน C# พร้อมตัวอย่าง

    Exception คือปัญหาที่เกิดขึ้นระหว่างการรันโปรแกรม C# Exception เป็นการตอบสนองต่อสถานการณ์พิเศษ เช่น การหารด้วยศูนย์ สามารถสร้าง Exception เองได้ โดยสืบทอดจากคลาส Exception ตัวอย่าง using System; namespace UserDefinedException { class TestFitness { static void Main(string[] args)

  3. Reference/Ref Parameter แบบอาร์เรย์ใน C#

    ประกาศ Reference Parameter ด้วยคีย์เวิร์ด ref Reference Parameter เป็นการอ้างอิงตำแหน่งหน่วยความจำของตัวแปร ไม่สร้างพื้นที่จัดเก็บใหม่เหมือน Value Parameter ประกาศ Ref Parameter แบบปกติ: public void swap(ref int x, ref int y) {} ประกาศ Ref Parameter แบบอาร์เรย์: static void Display(ref int[] myArr)

  4. Recursive Method Call (การเรียกเมธอดซ้ำ) ใน C#

    Recursive Method Call ใน C# เรียกว่า Recursion ตัวอย่างการคำนวณยกกำลังด้วย Recursion: หากกำลัง (p) ไม่เท่ากับ 0 ให้เรียกฟังก์ชันซ้ำ (Recursion): if (p != 0) { return (n * power(n, p - 1)); } ตัวแปร n คือฐาน และ p ลดลงทีละ 1 ในแต่ละรอบ ตัวอย่าง using System; using System.IO; public class Demo {

  5. Sealed Class ใน C# คืออะไร

    Sealed Class ใน C# (ใช้คีย์เวิร์ด sealed) ไม่สามารถสืบทอด (Inherit) ได้ คีย์เวิร์ด sealed สามารถใช้กับเมธอดได้เช่นกัน เมื่อใช้กับเมธอด เมธอดนั้นจะสูญเสียความสามารถในการ Override เมธอด sealed ต้องเป็นส่วนหนึ่งของ Derived Class และต้องเป็น Overridden Method ตัวอย่าง Sealed Class using System; using Sy

  6. Static Class ใน C# คืออะไร

    Static Class ใน C# ไม่สามารถสร้างอินสแตนซ์ (Instantiate) ได้ และสามารถมีสมาชิกแบบ Static เท่านั้น Static Class เป็น Sealed (ไม่สามารถสืบทอดได้) และไม่มี Instance Constructor ตัวอย่าง using System; public static class Demo { public static float PI = 3.14f; public static int calc(int n) { ret

  7. Static Constructor ใน C# คืออะไร

    Static Constructor เป็น Constructor ที่ประกาศด้วยคีย์เวิร์ด static เป็นบล็อกโค้ดแรกที่ทำงานในคลาส และทำงานเพียงครั้งเดียวตลอดวงจรชีวิตของคลาส ตัวอย่าง using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Difference { class Demo { static int

  8. Static Polymorphism ใน C# คืออะไร

    Static Polymorphism (หรือ Static Binding) คือการเชื่อมโยงฟังก์ชันกับออบเจกต์ในขณะคอมไพล์ (Compile Time) C# รองรับ 2 เทคนิค: Function Overloading - การกำหนดฟังก์ชันชื่อเดียวกันหลายรูปแบบ Operator Overloading - การกำหนดพฤติกรรมของ Operator ใหม่ Function Overloading สามารถมีการนิยามฟังก์ชันชื่อเดียวก

  9. โครงสร้าง (Structure) ใน C# คืออะไร

    โครงสร้าง (Structure หรือ Struct) ใน C# เป็นประเภทข้อมูลแบบ Value Type ใช้สำหรับจัดกลุ่มข้อมูลที่เกี่ยวข้องกันแต่มีชนิดข้อมูลต่างกัน ใช้คีย์เวิร์ด struct ในการสร้าง คุณสมบัติของ Struct สามารถมี Methods, Fields, Indexers, Properties, Operators และ Events ได้ สามารถมี Constructor ได้ แต่ไม่มี Destruc

  10. Interface ใน C# คืออะไร

    Interface กำหนดสมาชิก ได้แก่ Properties, Methods และ Events โดยมีเพียงการประกาศ (Declaration) เท่านั้น คลาสที่สืบทอด (Deriving Class) จะเป็นฝ่ายนำไป Implement จริง Interface ช่วยให้โครงสร้างมาตรฐานที่คลาสลูกต้องปฏิบัติตาม รูปแบบการประกาศ Interface: public interface InterfaceName { // interface m

  11. การทำ Serialization ของออบเจกต์ใน C#

    สำหรับการทำ Serialization ของออบเจกต์ ให้ใช้เมธอด BinaryFormatter.Serialize(stream, reference) ตัวอย่างโค้ดด้านล่างแสดงการ serialize ออบเจกต์แบบง่าย กำหนด Constructor: public Employee(int id, string name, int salary) { this.id = id; this.name = name; this.salary = salary; } ตั้งค่า FileS

  12. การสร้าง Exception แบบผู้ใช้กำหนด (User-defined Custom Exception) ใน C#

    Exception ใน C# ถูกแทนด้วยคลาส คลาส Exception หลักๆ มาจาก System.Exception โดยตรงหรือโดยอ้อม คุณสามารถสร้าง Exception ของตัวเองได้ โดยสืบทอดมาจากคลาส Exception ตัวอย่าง using System; namespace UserDefinedException { class TestTemperature { static void Main(string[] args) {

  13. วิธีเข้าถึงองค์ประกอบจาก Jagged Array ใน C#

    Jagged Array คืออาร์เรย์ของอาร์เรย์ (Array of Arrays) เพื่อเข้าถึงองค์ประกอบ ให้ระบุดัชนีของอาร์เรย์ย่อยที่ต้องการ ตัวอย่าง Jagged Array ที่มี 5 อาร์เรย์ย่อยของจำนวนเต็ม: int[][] a = new int[][]{new int[]{0,0},new int[]{1,2}, new int[]{2,4},new int[]{ 3, 6 }, new int[]{ 4, 8 } }; หากต้องการเข้าถึงอง

  14. วิธีเข้าถึงองค์ประกอบจากอาร์เรย์หลายมิติใน C#

    เพื่อเข้าถึงองค์ประกอบจากอาร์เรย์หลายมิติ (Multi-dimensional Array) ให้ระบุดัชนีขององค์ประกอบที่ต้องการ เช่น: a[2,1] คำสั่งด้านบนจะเข้าถึงองค์ประกอบที่แถวที่ 3 คอลัมน์ที่ 2 (ดัชนีเริ่มจาก 0) ซึ่งคือค่า 3 ตามตัวอย่างอาร์เรย์ [3,4] ด้านล่าง: 0 0 1 2 2 4 3 6 ตัวอย่างโค้ด using System; namespace Progra

  15. วิธีแปลงตัวอักษรพิมพ์เล็กเป็นพิมพ์ใหญ่ใน C#

    หากต้องการแปลงตัวอักษรพิมพ์เล็ก (Lowercase) เป็นพิมพ์ใหญ่ (Uppercase) ใน C# ให้ใช้เมธอด ToUpper() สมมติว่าคุณมีสตริงดังนี้: str = david; เพื่อแปลงสตริงพิมพ์เล็กด้านบนให้เป็นพิมพ์ใหญ่ ให้ใช้เมธอด ToUpper() ดังนี้: Console.WriteLine(Converted to UpperCase : {0}, str.ToUpper()); ตัวอย่างโค้ด using Syst

  16. พารามิเตอร์แบบ Value, Reference และ Output ใน C#

    พารามิเตอร์แบบ Value (Value Parameters) พารามิเตอร์แบบ Value จะคัดลอกค่าจริงของอาร์กิวเมนต์ไปยังพารามิเตอร์แบบทางการ (Formal Parameter) ของฟังก์ชัน การเปลี่ยนแปลงค่าพารามิเตอร์ภายในฟังก์ชันจะไม่ส่งผลต่ออาร์กิวเมนต์ต้นฉบับ นี่คือกลไกเริ่มต้นในการส่งพารามิเตอร์ไปยังเมธอด พารามิเตอร์แบบ Reference (Ref

  17. วิธีแปลงมุมตรีโกณมิติเป็นเรเดียนใน C#

    เพื่อแปลงมุมตรีโกณมิติจากองศา (Degrees) เป็นเรเดียน (Radians) ให้คูณด้วย Math.PI/180 ตัวอย่างโค้ด using System; class Program { static void Main() { Console.WriteLine(Math.Cos(45)); // ผลลัพธ์ไม่ถูกต้องเพราะรับค่าเป็นเรเดียน double res = Math.Cos(Math.PI * 45 / 180.0); // แป

  18. วิธีแปลงตัวอักษรพิมพ์ใหญ่เป็นพิมพ์เล็กใน C#

    หากต้องการแปลงตัวอักษรพิมพ์ใหญ่ (Uppercase) เป็นพิมพ์เล็ก (Lowercase) ใน C# ให้ใช้เมธอด ToLower() สมมติว่าคุณมีสตริงดังนี้: str = TIM; เพื่อแปลงสตริงพิมพ์ใหญ่ด้านบนให้เป็นพิมพ์เล็ก ให้ใช้เมธอด ToLower() ดังนี้: Console.WriteLine(Converted to LowerCase : {0}, str.ToLower()); ตัวอย่างโค้ด using System

  19. Generic Collections ใน C# (List, SortedList)

    Generic Collections ใน C# ได้แก่ List<T>, SortedList<TKey, TValue> ฯลฯ List<T> Generic Collection ขนาดไดนามิก ต่างจาก ArrayList (Non-generic) ตัวอย่าง List using System; using System.Collections.Generic; class Program { static void Main() { List<string> myLis

  20. Generic Delegates ใน C# (Delegate แบบ Generic)

    Generic Delegates ไม่ต้อง Define Delegate Statement เอง อยู่ใน Namespace System กำหนด Generic Delegate ด้วย Type Parameters: delegate T myDelegate<T>(T n); ตัวอย่าง using System; using System.Collections.Generic; delegate T myDelegate<T>(T n); namespace GenericDelegateAppl { class

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