Join Gerry O'Brien for an in-depth discussion in this video Introducing encapsulation, part of Learning C#.
When we create our class files, it's…important that we maintain control over the data.…And, what I mean by that is making sure that we…have control over the values that get assigned to our member variables.…And in this case type, color, weight, height, et cetera.…We've used the private modifier, the…private access modifier on these member variables.…Which essentially means that we cannot set them directly from within code.…So, in other words if we go to our program.cs file, which…is the main entry for our code execution on this console application.…
And we create an animal, Dog, as an example.…So, we're going to create a new instance of an animal called Dog.…We want it to assign something to the Dog.…So if we said Dog.Age, it's not available.…So, we can't make any kind of changes to Dog…in terms of the member variables because they're declared as private.…Again, it's very important for us to do that, so that we can…control the values that get assigned, or get sent into these member variables.…We don't want a negative value being sent into age.…
- Installing C#
- Working with loops
- Controlling program flow
- Using variables
- Building functions
- Creating and instantiating classes
- Catching errors
- Managing resources with the garbage collector
- Building collections
Skill Level Beginner
1. Introducing C#
2. C# Language Elements
3. Object-Oriented Programming in C#
4. Structured Exception Handling
5. Resource Management in C#
6. Extensible Types in C#
7. Windows Apps in C#
- 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.