From the course: C# Best Practices for Developers

Unlock the full course today

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

Related objects needed always

Related objects needed always - C# Tutorial

From the course: C# Best Practices for Developers

Start my 1-month free trial

Related objects needed always

- [Instructor] Okay, so we are ready to test our second scenario. That is where we always want to have access to the agency within the actor object. So, in this case, what we can do is create a property for the agency inside the actor class, and modify "Get Agency" to reference it. So, let's go over to our actor class, and, right above our last property, I'll go ahead and create a new one. Propfull tab, and our type will be "Agency", and this will be our current agency. Public field will be called "Current Agency" with a capital C. And, now, we'll scroll on down to where we have our Get Agency, and let's comment out this line where we're creating a new instance, and we are now going to refer to the property, Current Agency. And let's go ahead and create a test. Let's go ahead and run our test "Get Agency", and we'll see that it fails. If we look at the bottom left-hand corner here, it'll say that we have a "no reference exception", and the reason why is because we need to go to our…

Contents