In a couple of weeks, I'll be teaching a class of first-year engineers the salient points of references in C# as part of their first-year programming course. Most of them have never programmed before, and had enough trouble learning objects, so teaching references is going to be an uphill battle. I plan to have lots of examples available for the students to go through on their own, but just showing a bunch of examples tends to be pretty overwhelming if the the underlying concept doesn't 'click'.
So I'll put the question out to the SO community: what's the best way you've seen references taught? What made it 'click' for you? Is there any reference-related material that I'm missing?
My tentative lesson plan is:
- What is a reference (using an argument like Eric Lippert's)
- References and the Garbage Collector
- Reference Types and Value Types
- Immutable Types
- Passing by Reference versus Passing by Value (and all of the subtleties of object references being passed by value)
- A handful of nasty examples that produce unexpected results if you don't understand 1-5.