-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Description
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.
- ID: 20935a57-1ba9-a5b8-0a30-cc68dac2e4e1
- Version Independent ID: 7c81da48-bf33-8c1a-f9fe-d02e056b2a07
- Content: C# Program Structure - A Tour of the C# Language
- Content Source: docs/csharp/tour-of-csharp/program-structure.md
- Product: dotnet-csharp
- GitHub Login: @BillWagner
- Microsoft Alias: wiwagn