From the course: Ten Tips for the C# Developer
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Use the ImmutableList collection - C# Tutorial
From the course: Ten Tips for the C# Developer
Use the ImmutableList collection
- [Instructor] Let's keep going with this theme of thread-safe code. On the last tip, I showed you how to take a RayPoint type and convert it into an ImmutableRayPoint type and then I did that by creating read-only properties and a parametrized constructor and I also created some special helper methods. One of the problems with the code that I wrote in the last example is that when you call GetShape, I'm returning a list of T, so the type ImmutableRayPoint is thread safe but the list of T that comes from the .NET framework is not thread safe so what we're going to do is modify our code so we're working with a thread-safe list. And there are many different collection classes in .NET that are thread safe. The one we're looking at for this example is called ImmutableList. Let's start by looking at the old code. Here in GetShape, I'm creating a list of T and populating it with list data. Now, because list of T is not…
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
-
-