From the course: Debugging in C#

Unlock the full course today

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

Using a reference like a value

Using a reference like a value

From the course: Debugging in C#

Start my 1-month free trial

Using a reference like a value

- [Instructor] Programmers are often used to being in control of whether the values they assign to variables are simply values or are references to existing objects. However, in C# the decision is made by the programmer who defined the object, not by the programmer who instantiates the object and assigns it to a variable. This is a common pitfall for those new to C#. Let's take a look at an example. If you're not sure whether the object you are using is a value or a reference type, you could run in to some errors. Lets take a look at this example. In this program we have a class called Person and each person has a string name which is initialized with the person constructor. Inside of the person class we also have a fictional character struct, where each fictional character has a fictional name and we assign that in the constructor. Lets run this code and see what happens. So here we get Rebecca, Rebecca, Harry Potter, Hermione Granger what does all that mean? Well in our main method…

Contents