Join Reynald Adolphe for an in-depth discussion in this video Auto-property initializers, part of C# 6.0 First Look.
- If you're a fan of auto-properties,…you'll likely appreciate auto-property initializers.…Just as the name implies, you can initialize…auto-properties default values with…a little less work than you did in the past.…Let's take a look at our Artist class.…In previous versions,…if you wanted to assign a default value,…we'd need to write a constructor, like this.…For writing constructors, I like to use a shortcut.…Type in C-T-O-R,…hit Tab, and boom,…it brings up the constructor.…
And if I wanted to just assign a default name value.…I'll type in Name = , and in our case,…we'll write A-List actor.…That's what we had to do in the past,…but now with the new version,…what we can do is actually assign that value…directly to our property.…So if we just copied and paste,…A-List actor,…and went to Name,…entered =,…paste in our value.…
That would be it.…And we no longer need a constructor,…because in the back end, the compiler…is assigning this value to a backing field.…And this might not seem like a huge deal,…but in the long run it can save time.…
- Introducing the new IDE in Visual Studio 2015
- Leveraging nameof expressions
- Using index initializers
- Using await in catch and finally blocks
- Using static
- Resolving conflict instance methods
Skill Level Beginner
1. Touring the Enhanced IDE
2. Expression-Level Features
3. Statement-Level Features
Adding exception filters2m 42s
4. Member Declaration and Initialization Features
5. Improved Debugging
- 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.