Join Reynald Adolphe for an in-depth discussion in this video Using properties demo, part of C# Best Practices for Developers.
- [Instructor] So, let's go ahead and demonstrate…using the setter to validate content…that is going to be referenced.…So, I'd like to jump to our Actor Test Class,…and what we're going to do is…to create another test for this purpose.…So, I will highlight Test Book Actor,…and let's go ahead, scroll down, and paste it.…
And we'll give this a name like…'Test Formatting on Setter for Book Actor',…and what I will do is change the name of the actor…to 'Johnny Boy' with several spaces right after it.…So, now, because I'm adding those spaces…the test should fail because it's not going to match…our expected value.…
So, let me right-click on Test Formatting on Setter…and Run Selected Test, and it fails just as we expected.…So, to fix this, let's go to our Actor Class…and find our actor name property,…and this is where the power of the setter comes in.…What we're able to do is to add in some logic here,…such as adding a formatted name variable…and the value that we assign on line 24…we're gonna go ahead and check that…and make sure that one - it's not nul…
- Naming and handling classes
- Running a unit test
- Using constructors
- Naming and handling methods, fields, and properties
- Using properties correctly
- Managing objects efficiently
- Common design patterns as best practices
Skill Level Intermediate
1. Best Practices: An Overview
2. Naming and Handling Classes
3. Naming and Handling Methods, Fields, and Properties
4. Managing Objects Efficiently
5. More Best Practices Resources
- 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.