- So we've seen a basic If statement at work.…I thought I'd show you a couple of…different formats for this.…Let's add another method to our flow control class.…This one is going to be very similar…to what we have on line ten.…This is going to be public bool IsYourFavoriteColorRed.…And this time I wanted to show you that…if you have only one thing in your If statement,…as we actually do in the blue version of this,…we don't really need to put the curly braces in there.…
So it looks like this.…We can say if(color.ToLower() == "red")…then we'll return true.…Otherwise, there's no need for an else here,…"return false;".…The reason this works is because…if it is actually red, then the statement returns here,…it exits the method and line 12 never actually runs.…But if it's false then it falls through to line 12,…and line 12 handles the return.…
It's a slightly more terse way of writing…what we have down here in the blue version.…And if you like terse, let me show you…an even more terse method,…and that's the ternery operator.…
Author
Released
1/19/2018- Writing unit tests in C#
- Working with simple and multidimensional arrays
- Managing ordered and unordered data with lists
- Evaluating conditions with if-else statements
- Using OR, AND, and NOT operators
- Building loops
- Debugging and handling exceptions
- Creating the final build of your C# project
Skill Level Beginner
Duration
Views
Related Courses
-
C#: Delegates, Events and Lambdas
with Joe Marini1h 9m Intermediate -
C# 7 First Look
with Reynald Adolphe1h 9m Beginner -
C# Object-Oriented Programming Tips and Tricks
with Jesse Freeman58m 39s Intermediate -
Learning C# Algorithms
with Reynald Adolphe1h 28m Beginner
-
Introduction
-
Welcome1m 17s
-
What you should know1m 48s
-
-
1. Unit Testing and Test-Driven Development
-
What is unit testing?1m 25s
-
Writing a unit test3m 53s
-
Running tests1m 57s
-
Setting up tab groups1m 16s
-
-
2. Arrays and Collections
-
Simple arrays4m 36s
-
Resizing arrays4m 4s
-
Working with simple arrays3m 53s
-
Working with lists2m 53s
-
Introduction to LINQ4m 25s
-
-
3. Flow Control
-
If-else, if-else statements2m 34s
-
Switch statements3m 40s
-
Logical NOT1m 26s
-
For loop4m 22s
-
Testing the assembly3m 56s
-
The foreach loop3m 38s
-
Do and do-while loops3m 23s
-
4. Exception Handling
-
Adding a console project4m 7s
-
Cleaning up with finally2m 3s
-
-
5. Getting to Production
-
Working with NuGet packages4m 18s
-
Logging with NLog6m 6s
-
Final build3m 7s
-
-
Conclusion
-
Next steps1m 57s
-
- 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.
CancelTake 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.
Share this video
Embed this video
Video: Alternate if-else formats and the ternary operator