@vitaminchik, thanks for the feedback,
There are some explanations about your question.
How does the method Concat() change the value of an object in variable -result?
a. The params MyStack[] elementsOfArray
convert the three MyStack object
to a MyStack array
.
b. The foreach statement get every MyStack
to get the property _stackItem.Values
(such as string(a,b,c,1,2,3).
c. Then we could get every result is "a", "b", "c", 1", "2", "3,"A", "B", "C"
.
And another question, what does the class field store Item Prev?
It used the following class constructor to set the Item property.
public StackItem(StackItem stackItem, string value)
{
_previousElement = _top;
_top = value;
Item = stackItem;//-> here used to set the Item property
Value = value;
}
public void Add(string value)
{
_top = value;
_count++;
_stackItem = new StackItem(_stackItem, value);
}
When calling Add method, it will call the constructor automatically.
In a conclusion, this program is used to nest StackItem
types, for example, the first is SItem (StackItem type
), the value is A, and the nested inside is Item (StackItem type
). The value is B, and so on.
And you could add a watch in visual studio to check his behaviour:
Hope my explanation could help you.
Best Regards,
Jack
If the answer is the right solution, please click "Accept Answer" and upvote it.If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.