Skip to content

Push/Pop Example #9576

@Mandated

Description

@Mandated

It's been about a year since I went through the C# docs, so I'm probably missing something mentioned somewhere. Even after loading the example into VS, I am unsure of the functional nature of the class type objects. It is hard for me to explain concisely, so I will walk through my understanding (combined example with the data supplied): Begin in main & create Stack obj 's' which has the field 'top' set to null. Invoke the Push method of s with an int arg of 1 supplied to satisfy the object 'data' parameter. This in turn assigns a new obj of class type 'Entry' to s's 'top' field, which means the field now represents the values of Entry's instance constructor's 'next' and 'data' fields (which themselves are set to the value of Entry's instance variables of type Entry and type object). (I'm ignoring the next two method calls to Push) We then have the call to Pop which is also a method of s's and do a conditional check to see if 'top' is null. It isn't so the field of type object, 'result', is assigned the value of 'top.data'. Then my brain explodes bc I'm not sure how the assignment of 'top' to 'top.next' effectively discards the prior data and moves it to the next referenced storage location.

It may be that I'm missing something that isn't shown in the locals or autos windows. Is this the way the array methods Push & Pop are represented internally? Thank you.


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions