this post was submitted on 03 Jul 2026
7 points (100.0% liked)
C Sharp
1801 readers
4 users here now
A community about the C# programming language
Getting started
Useful resources
- C# documentation
- C# Language Reference
- C# Programming Guide
- C# Coding Conventions
- .NET Framework Reference Source Code
IDEs and code editors
- Visual Studio (Windows/Mac)
- Rider (Windows/Mac/Linux)
- Visual Studio Code (Windows/Mac/Linux)
Tools
Rules
- Rule 1: Follow Lemmy rules
- Rule 2: Be excellent to each other, no hostility towards users for any reason
- Rule 3: No spam of tools/companies/advertisements
Related communities
founded 3 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
Wow I didn't know. Thank you for pointing that out.
I know in C# you can just pull from data structures using an index, so can I do
stack[0]? Would that be the same as Java'sstack.elementAt(0)?Stack doesn't actually allow indexing, and ElementAt is an extension method implemented by accessing Stack's iterator. My honest recommendation is to not use Stack, even if that's what the book was using. Stacks are not really meant to be traversed. They're meant to be pushed to, and popped (or peeked) from. Each ElementAt call requires O(N) time to retrieve. I recommend switching to List and implementing 'push', 'pop', and 'peek' as such:
However, I understand that is a bit of a change. If you'd prefer to keep it as a stack, a simple reversal of the for loop can get the job done.
That's enough to get these scripts running.
By the way, I noticed that redefining a global variable will crash as well, but a scoped variable will display an error as intended.
Thanks for bringing that global variable issue to my attention, I'll have to look into it.
As for the stack, I'll traverse it in reverse for now, I may come back once I've finished the interpreter to clean up the code and add more features.