1

visual basic.net by Jesse Liberty

This image is from visual basic.net by Jesse Liberty. I just wanted to know that what the author is trying to say here. Does vb.net array only contains references to the value type variables allocated on the stack or the array contains actual values on the heap.

Nikhil kumar
  • 151
  • 1
  • 7
  • Does this answer your question? [Arrays, heap and stack and value types](https://stackoverflow.com/questions/1113819/arrays-heap-and-stack-and-value-types) – 41686d6564 stands w. Palestine Feb 20 '20 at 03:54
  • [Any tool to see where variables are stored while a .NET program is executing? Is it on the stack or heap?](https://stackoverflow.com/a/14023708/7444103) – Jimi Feb 20 '20 at 04:25
  • [The Truth About Value Types](https://blogs.msdn.microsoft.com/ericlippert/2010/09/30/the-truth-about-value-types/) – Jimi Feb 23 '20 at 05:32

1 Answers1

1

There are no pointers in VB.NET so it's not possible for an array to contain pointers. You can basically think of an array as a group of variables. Each element of an array behaves pretty much exactly like a variable of the same type behaves.

All variables are Nothing by default, so all array elements are Nothing by default. Value type variables contain a value, so getting that variable gives you a copy of the value. The same is true of elements in an array of a value type. Reference type variables contain a reference to an object, so getting that variable gives you a copy of that reference to the same object. The same is true of elements in an array of a reference type. In simple terms, structures are value types and classes are reference types so an array of structures contains those objects in the elements while an array of classes contains references to those objects in the elements.

jmcilhinney
  • 50,448
  • 5
  • 26
  • 46