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.

Be more functional with the conditional operator

Be more functional with the conditional operator - C# Tutorial

From the course: Ten Tips for the C# Developer

Start my 1-month free trial

Be more functional with the conditional operator

- [Instructor] Programmers are always trying to write better code. And we often express this in patterns. In other words, if you write your code using this pattern, you'll have more robust or more secure code. I have been studying the functional programming patterns. I even created a course called "Functional Patterns for C#" and the code that we're looking at in this tip is from that course. We're going to to look at two principles of functional programming and how to rewrite your code to meet those principles. One principle in functional programming is to avoid state mutation, or side effects, in your code. This is called a pure function. You strive to write pure functions. And you also strive to replace your statement-based code with expressions. Let's start by taking a look at the code. I have a class called product that, in this case, I've instantiated it. It's name is Microphone and it's retail price is 200.…

Contents