struct vs class | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

struct vs class

I have a program with a dictionary of objects. During runtime anywhere from 400 to 500 objects are in the dictionary. The objects are largely a group of simple data types, but are over 16 bytes and get updated/modified on a continuous basis. They never need to be boxed. Should I use structs or classes? What are the advantages of each?

26th May 2020, 12:03 AM
Matthew Shoop
Matthew Shoop - avatar
2 Answers
0
I realize that what I really need to do is write both and do performance testing.
26th May 2020, 12:36 AM
Matthew Shoop
Matthew Shoop - avatar
0
Those four qualifications come from Microsoft, but Microsoft is not internally consistent with sticking to those guidelines. For example (from the same SO post) the Entry of the Dictionary class is a struct. I was wondering really if anyone has performance data on structs violating only 2 and 3 of the above. Again, I'm likely going to have to do performance testing myself. I also might be better off with a SortedList instead of a Dictionary. Again will need to do testing.
26th May 2020, 1:48 AM
Matthew Shoop
Matthew Shoop - avatar