Tuesday, 7 August 2018

c# - When to use struct?

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 logically hold them all together into a cohesive whole.



I came across these rules here:




  • A struct should represent a single
    value.


  • A struct should have a memory
    footprint less than 16 bytes.

  • A struct should not be changed after
    creation.



Do these rules work? What does a struct mean semantically?

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print ...