This video looks at the implications of "throw" in C# 7 changing from a statement to an expression.
- [Instructor] Prior to C# 7, throw…was implemented as a statement.…That means that it could not be used…in some areas like conditional expressions,…null-coalescing expressions and…some other edge cases as well.…In C# 7, throw is now an expression…and, as such, it can be used in those cases.…So, let's open the CarDetailViewModel…and we're going to scroll down and look…at the quantity property and here we have…a check to see if the value is less than zero.…
If it is, it throws an argument…out of range exception.…The code is written here is likely…what you would have seen prior…to C# 7 but with C# 7 we can now use…a conditional expression to do the same thing.…So, I'm going to copy the throw out…of the range check up here…and remove the if statement…and right in the set property…I'm going to see if the value is less than zero…and, if it is, I'm going to paste that throw…right in here and, if not,…I'm going to use the value itself.…
With throw changed into a statement,…we can now simplify how we structure…this piece of code.…
- Working with tuples
- Using C# throw expressions
- Inspecting UI structures with Xamarin Inspector
- Identifying memory leaks in iOS and Android
- Recording and playing back tests with Test Record
- Using embedded assemblies in Android
Skill Level Intermediate
1. C# 7 Language Improvements
Inspecting UI structures3m 34s
4. Test Recorder
5. Embedded Assemblies
Where to go from here1m 54s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.