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 - C# Tutorial
From the course: Ten Tips for the C# Developer
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
-
-
-
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
-
-