From the course: Grasshopper and Rhino: C# Scripting

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Reference vs. value types

Reference vs. value types

From the course: Grasshopper and Rhino: C# Scripting

Start my 1-month free trial

Reference vs. value types

- [Instructor] Earlier in the course, I introduced the idea that an object, can either be a value or reference type object. So let's take a closer look at these two types. These types differ in the way that they store data in memory. A value type will store data within its own memory allocation, in a single space in memory. What this means is that when we allocate a value type, like the number 100, to a variable named, i, for example, the data 100 is stored directly with the variable i in memory. This makes the data fast to access. The impact that this has on our code, is that if we were to make another variable, say j, which was to equal i, it would basically create a copy of that value, which will be stored in memory with the variable j. And the location for i is unaffected. Value types, are those created with a struct instead of a class, like an int Boolean or double. With reference types, the data is not stored…

Contents