From the course: Advanced C#: Functional Programming Patterns

Unlock this course with a free trial

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

Instance method in immutable type

Instance method in immutable type - C# Tutorial

From the course: Advanced C#: Functional Programming Patterns

Instance method in immutable type

- [Narrator] Our Color class has three read-only properties red, green, and blue. And it has the constructors for setting those values or one single constructor cause I removed the one parameter constructor from the last example. And now what I want to talk about in this video is what you're going to do if you're going to create an instance method or function on this Color class. So there's two general categories of instance methods. One is you pass in a parameter, you modify the state of the immutable type, and then you return a new instance of the type. And I'll talk about that later in this chapter. What we're looking at in this video is if you're creating an instance member or an instance method, that's doing some other calculation and those need to be pure. So here's a real world example that you're going to have to do in your types. If you want to override ToString, this represents the formatted string…

Contents