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 - C# Tutorial
From the course: Ten Tips for the C# Developer
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
-
-
-
Avoid race condition with TryGetValue method1m 46s
-
(Locked)
Better switch statements with pattern matching6m 42s
-
(Locked)
Readable literals with the underscore4m 8s
-
(Locked)
Extract items from sequence with indices9m 8s
-
(Locked)
Discard feature5m 3s
-
(Locked)
Be more functional with the conditional operator2m 42s
-
(Locked)
Create a thread-safe immutable type5m 13s
-
(Locked)
Use the ImmutableList collection4m 14s
-
(Locked)
Show custom debugger information4m 49s
-
(Locked)
Work with nested collections and SelectMany2m 45s
-
-