[C#] Struct VS Class

struct
- object อยู่บน stack 
- มี default constructor เสมอ ไม่ว่าจะมี custom constructor หรือไม่สร้างก็ตาม
- value type
- รู้ life time ของ object (out of scope)

-มี Method (ในภาษา C จะไม่มีนะ)

class
- object อยู่บน manage heap
- ถ้ามี custom constructor จะไม่มี default constructor
- reference type
- ไม่รู้ life time ของ object เพราะ GC จะเป็นตัวจัดการ


Discover more from naiwaen@DebuggingSoft

Subscribe to get the latest posts to your email.