[DotNet] Class or Struct

To be frank, with powerful server and cpu and SSD discs, I don’t use struct much. however, it is still necessary to understand the difference between them.

I think the most difference point is that Class is reference type and struct is value type. class is called by reference, which means changes to an instance of a reference type will affect all references pointing to the instance.  while value type assignment is just value copy. value type is immutable.

Generally speaking, the cost of Struct is less than Class. but class is much much more flexible.

When creating desktop application, games, I think struct shall save you a lot of memory.

blog comments powered by Disqus