What are the criteria on which to decide when a tree node should be a struct or a class?
3 Answers
i would go for class becuase you can pass node as reference but not on the struct which will be passed as a copy of original
and you would require a lot of manupulation on nodes so passing them as a reference sometime results in performance boostup.
and if you are storing a lot of data in the your node tahn struct would not be a choice.
i am not pointing out which is more faster value or refernce types that totally depends on scenarios.

- 17,262
- 5
- 38
- 63
-
I go for classes also on a regular basis. I rarely use structs. But is just a personal preferance. – Liviu Mandras Nov 19 '10 at 10:29
Structs are usually more lightweight and are considered value types. Classes are reference types.
Consider this post also: Which is best for data store Struct/Classes?

- 1
- 1

- 6,540
- 2
- 41
- 65
-
The term "lightweight" is a bit misleading in this context. As structs are always copied when passed around, larger structs can be quite "heavyweight". In .NET you almost always want to use a class unless you are doing P/Invoke or you have the rare case that you need a custom value type. – Dirk Vollmar Nov 19 '10 at 10:59
-
While modifying the tree, you need at least 2 pointers/references to the same "data", this is hard to do with structs, unless you box (convert to object) them explicitly.

- 52,015
- 16
- 101
- 139