2

What are the criteria on which to decide when a tree node should be a struct or a class?

Dave
  • 21
  • 1

3 Answers3

1

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.

TalentTuner
  • 17,262
  • 5
  • 38
  • 63
0

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?

Community
  • 1
  • 1
Liviu Mandras
  • 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
  • Please see my comment to saurabh. – Liviu Mandras Nov 19 '10 at 13:22
0

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.

GvS
  • 52,015
  • 16
  • 101
  • 139