When should I use a struct rather than a class in C#?

前端 未结 28 2730
予麋鹿
予麋鹿 2020-11-21 11:55

When should you use struct and not class in C#? My conceptual model is that structs are used in times when the item is merely a collection of value types. A way to

28条回答
  •  自闭症患者
    2020-11-21 12:16

    Struct can be used to improve garbage collection performance. While you usually don't have to worry about GC performance, there are scenarios where it can be a killer. Like large caches in low latency applications. See this post for an example:

    http://00sharp.wordpress.com/2013/07/03/a-case-for-the-struct/

提交回复
热议问题