Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> C#

คุณสมบัติหลักของภาษา C# Programming

C# เป็นภาษาโปรแกรมมิ่งแบบ Modern, General-purpose, Object-oriented ที่พัฒนาโดย Microsoft ออกแบบสำหรับ Common Language Infrastructure (CLI) ซึ่งประกอบด้วย Executable Code และ Runtime Environment ที่อนุญาตให้ใช้ภาษาระดับสูงต่างๆ บน Platform และ Architecture ที่หลากหลาย

คุณสมบัติหลัก (Major Features) ของ C#

Feature คำอธิบาย ประโยชน์
Boolean Conditions ชนิดข้อมูล bool แท้จริง (true/false) ลด Bug จากการใช้ int แทน Boolean, โค้ดอ่านง่าย
Automatic Garbage Collection GC จัดการ Memory อัตโนมัติ ไม่ต้อง Free Memory เอง ป้องกัน Memory Leak
Standard Library (BCL) Base Class Library อันกว้างขวาง Collections, IO, Networking, Crypto, XML, JSON ฯลฯ
Assembly Versioning รองรับ Versioning ของ Assembly แก้ปัญหา DLL Hell, Side-by-side Execution
Properties & Events Syntax Sugar สำหรับ Encapsulation และ Observer Pattern Clean Syntax, Data Binding, Notification
Delegates & Events Management Type-safe Function Pointers, Multicast Delegates Callback, Event-driven, Async Programming
Easy-to-use Generics Generic Types/Methods กับ Type Constraints Type Safety, Performance (No Boxing), Reusability
Indexers เข้าถึง Object เหมือน Array (obj[index]) Custom Collections, Dictionary-like Access
Conditional Compilation #if DEBUG, ConditionalAttribute Debug/Release Build แยกกัน, Feature Flags
Simple Multithreading Thread, Task, async/await, Parallel Concurrency, Parallelism, Responsive UI
LINQ & Lambda Expressions Language Integrated Query, Functional Style Query Data แบบ Declarative, Type-safe
Integration with Windows WPF, WinForms, UWP, WinUI, MAUI Native Windows Development

คุณสมบัติสมัยใหม่ (Modern C# Features)

Version Key Features
C# 7-8 Tuples, Pattern Matching, Local Functions, Nullable Reference Types, Default Interface Methods
C# 9 Records, Init-only Properties, Top-level Statements, Pattern Matching Enhancements
C# 10 Global Using, File-scoped Namespaces, Record Structs, Interpolated String Handlers
C# 11 Raw String Literals, Generic Math, Required Members, Auto-default Structs
C# 12 Primary Constructors, Collection Expressions, Alias Any Type, Experimental Attribute
C# 13 Params Collections, Extension Types, Implicit Indexer Access, Ref Struct Interfaces

ประเภทข้อมูลพื้นฐาน (Type System)

  • Value Types: struct, enum, Primitive Types (int, double, bool...) - Stored on Stack
  • Reference Types: class, interface, delegate, string, array - Stored on Heap
  • Nullable Types: int?, DateTime? - Value Types ที่สามารถเป็น Null ได้

Memory Management

  • Stack: Value Types, Local Variables, Method Parameters - Fast, Auto-cleanup
  • Heap: Reference Types, Objects - Managed by GC
  • GC Generations: Gen 0 (Short-lived), Gen 1, Gen 2 (Long-lived) - Optimized Collection
  • IDisposable / using: Deterministic Cleanup สำหรับ Unmanaged Resources

Cross-Platform (.NET Core / .NET 5+)

  • รันบน Windows, Linux, macOS
  • Single Binary Deployment (Self-contained)
  • Container Ready (Docker)
  • Cloud Native (ASP.NET Core, gRPC, Minimal APIs)