From the course: Ten Tips for the C# Developer

Unlock the full course today

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

Create a thread-safe immutable type

Create a thread-safe immutable type - C# Tutorial

From the course: Ten Tips for the C# Developer

Start my 1-month free trial

Create a thread-safe immutable type

- [Instructor] There's a good chance that the code you write is going to run on a multi-threaded device. Our phones, our computers all have multiple CPUs. They all have multiple threading capabilities. And that means we need to think about how to protect our code. And so that we don't run into race conditions and we don't have data corruptions and things like that. And there's a principle that's been around for a long time called immutable types. If you create an immutable type, you can't change the data from multiple threats. That's what we want to look at in this tip. I'll take this RayPoint class I have here, and I will turn this into an immutable version of this class. Now, a couple of things I'd like to talk about before I show you the code is, I'm doing a simplistic overview in this tip. There are some nuances that I'm not showing here. If you want to learn more, I've created some videos in my functional…

Contents