Hi amigo, so if I rightly understood it's almost the same principle with both value and ref types, changing the stored place (stack / heap) but same use and behaviour of the ref keyword. Maybe because it all happens inside an array which is by its own a reference type? Thank's in advance y buena onda
EDIT: is good to account that strings behaviour as a value type by .net devs will, so maybe it's also for this reason. I think if we use ref with a class instance it would gonna change behaviour, am I right? Saluto
Hi Elia, First I should mention that strings are reference types just like classes. Second, it doesn't matter that it was an array or not, just focus on what we were working on, which in this example was an element of an array and when we use an index to refer to that element, we receive a copy of the value inside that index of the array not a reference to it. In case of array of integers we received a copy of integer and in case of array of strings, we got a copy of the string's reference. but after we used ref keyword, we got a reference to that integer's location in heap, and a reference to the location which stores the reference of string's location! So no matter what, ref returns the address not the value.
Do you know about any other places that we can use ref keyword? tell me!
very good
Hi amigo, so if I rightly understood it's almost the same principle with both value and ref types, changing the stored place (stack / heap) but same use and behaviour of the ref keyword. Maybe because it all happens inside an array which is by its own a reference type? Thank's in advance y buena onda
EDIT: is good to account that strings behaviour as a value type by .net devs will, so maybe it's also for this reason. I think if we use ref with a class instance it would gonna change behaviour, am I right? Saluto
Hi Elia, First I should mention that strings are reference types just like classes. Second, it doesn't matter that it was an array or not, just focus on what we were working on, which in this example was an element of an array and when we use an index to refer to that element, we receive a copy of the value inside that index of the array not a reference to it.
In case of array of integers we received a copy of integer and in case of array of strings, we got a copy of the string's reference. but after we used ref keyword, we got a reference to that integer's location in heap, and a reference to the location which stores the reference of string's location! So no matter what, ref returns the address not the value.