I was refreshing on my pointer skills by reading about linked lists and it got me wondering how C# handles it's lists. Lets say I have a global list of type Foo
List<Foo> globalList = new List<Foo>();Now lets say I create an instantiate a Foo object within a local scope of a function.
void LocalFunction()
{
Foo myLocalObject = new myLocalObject();
//Do stuff with myLocalObject
globalList.Add(myLocalObject);
}
From what I understand with c++, globalList.Add(myLocalObject); is passing the object by address (which is how c# passes classes anyway) so even though myLocalObject is no longer in scope, I can still access it and it's information by using globalList[whateverIndexItsat].whateverMethod();
I'm able to do this because C# has a pointer internally somewhere in which it is pointing to the memory created by that localObject. Is my understanding of this correct? Also, does the garbage collector manage the pointers by reference counting?
I'm just curious as to how everything is working here and the linked list datastructure in C++ is helping me understand where to use pointers a little better.
Thanks, hopefully I'm understanding this correctly.






