I know there are no pointers in C#, but I am trying to figure out how to do the following, which I would have done with pointers (or better yet, iterators) in C++ (I am taking a course in C#, but I already know C++).
We got an assignment to write a simple “store” program (inventory, transactions, etc.). My first idea (coming from C++) was this: have a linked list of items and their amount in stock. Then, have a class representing a sale, which has a list of the items in the current sale, where each item is represented as an iterator to specific items in the master stock list and a value for the amount. (I hope this is clear.)
I tried to do the same in C# but can’t figure out how to get those iterators to the master list (they should preferably also be good across updates to the master list).
How do you do this?
You don’t need to do anything special to use references, they are used by default in C#.
I’m assuming you’d do something like this in C++:
In C#, since it uses references rather than pass by value by default, you get that behavior by default. You’d get similar behavior in C# from the following code:
To call this C# code you could just do something like