Yes, all of the List
objects are stored on the heap either way. However, without the ref
keyword, you can't reassign the inList
parameter and have it affect the caller's scope. When you create a new List
object, it goes on the heap as a new object, but the original reference in the caller's scope is not affected unless you use the ref keyword.
In WithoutRef
, if you call methods on the existing List
without redefining it, you will see that it is modified:
inList.Clear();
inList.Add(1);