Answer the question
In order to leave comments, you need to log in
How do passing different reference types as a parameter to a method work, and did I understand correctly how an array is arranged in memory?
Good day! Now I'm experimenting with passing objects of different reference types as a parameter to a method and understanding their behavior inside the method. Experimenting, I also understood how arrays work when passing them as a parameter, but I understood how they work in a method only after understanding how they are arranged in memory. And here are two (to whom I'm lying, three) questions that arose during the whole experiment:
1. Did I correctly understand the behavior of an array, objects of reference types and a delegate when passing them as a parameter?
If not, please explain.
https://photos.app.goo.gl/84wbQj2VszqfDWUE7
2. How does the place I highlighted in the code on line 56 work?
https://photos.app.goo.gl/mo3YMBdPJYfWPu4e7
3. Did I understand correctly how an array is arranged in memory?
If not, please explain how?
https://photos.app.goo.gl/ggacpoani1Seznxj8 - array in memory
Answer the question
In order to leave comments, you need to log in
https://youtu.be/KbuJdkPLAjw look at this, a lot will fall into place.
The reference type is therefore called as the reference is passed to the method, and is not cloned before the call, unlike value types.
well, they would copy the code, there is syntax highlighting on the toaster. Trying to make out something in the screenshots is a pain. One of them is also shrunk to the point that it is difficult to make out something. Well, even better - to formulate specific questions, and ask them separately. It is difficult to answer 5 screenshots with code and pictures at once.
But according to what I noticed - you need to put a couple of facts in your head. And then everything will fall into place.
1) everything is an object
2) all value types (honestly, I fell into a stupor trying to remember the correct translation) are also inherited from object (more precisely, from ValueType, which is already inherited from object). And at the compiler level, there is a check whether the class inherits from ValueType in order to know how to work with it further (i.e. where to store and how to transfer)
3) on the one hand, the string is also an object, and on the other hand, the string is immutable. so any attempt to change it will actually create a modified copy of the string.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question