From the course: Advanced C#: Functional Programming Patterns

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Use an immutable argument

Use an immutable argument

- [Instructor] The real issue with the previous example is that the list of T is immutable type and when I passed in that as a parameter, I was able to add items to the list, remove items to list. I could find an individual item on the list and change the value of it and that location, so that, that's the danger. I'm passing in the parameter and I'm not careful, I could mutate the internal state of that list. The way we get around this is to try to make our arguments immutable. And I'll talk more about immutability in the next chapter. I'd like you to know, though, that there are a number of collection classes in .NET that are thread-safe. There's the concurrent collections and there's also the immutable types, the ImmutableList. And so I thought I would show you a quick example of using the ImmutableList<T>. It looks the same when you declare it here on line 29. However, there's not a standard constructor. If…

Contents