สรุป features ใหม่ๆ ใน C# 9 ที่เปิดตัวในงาน Microsoft Build 2020

Tags: c#

สรุป features ใหม่ๆ ของ C# ที่เพิ่งเปิดตัวไปในช่วงงาน Microsoft Build 2020

เนื้อหาทั้งหมดสามารถอ่านได้จากบทความนี้ครับ https://devblogs.microsoft.com/dotnet/welcome-to-c-9-0/

features หลายตัวเป็นการนำ functional programming paradigm เข้ามา implement มากขึ้น และบางตัวก็พัฒนาให้ดียิ่งขึ้น ตัวอย่างที่เห็นชัดๆ คือ เรื่อง immutable object, property, improvement of pattern matching

ตัวอย่าง features ใหม่ที่น่าสนใจ

  • Init-only properties และ Records เพื่อสร้าง immutable property และ object
  • Top-levelop programming ที่ไม่ต้องมี main
System.Console.WriteLine("Hello World!");
  • pattern matching ที่พัฒนาขึ้นช่วยให้เขียน code ได้กระชับขึ้น
  • พวก target type ใน new keyword และตัดปัญหาความสับสนในการใช้งาน ?? และ ?: condition
  • Covariant returns ที่ child class จะมี return type ที่ specific ได้มากขึ้นกว่า return type ของ base class