I want to build 2 Tree structures. The first Tree will contain nodes, each with List of my Range
object:
class Range {
public DateTime Start { get; set; }
public DateTime End { get; set; }
}
The Tree structure will look like this:
I then want a 2nd Tree build from the 1st Tree. It will have a similar structure, however, when changes are made to the Range object in the 2nd Tree, I want the Range objects in the first tree to also change. Effectively, I need to hold references or pointers to the Range objects in the first Tree:
Tree #2:
C# is my language of preference and I know you can use the ref
keyword, but I wonder if C# is really the right language for this or do I need something with pointers like C++?
Yes you can.
You declared Range as class
(as opposed to struct
), therefore you will only be handling references (as opposed to the actual values).
For instance, your List<Range>
is a collection of references to Range
objects.
Range
having reference semantics means a few things in C#, for example:
Range
variable can hold null
You may like a quick refresher on reference vs. value semantics.