Join Reynald Adolphe for an in-depth discussion in this video Constants vs. read-only fields, part of C# Best Practices for Developers.
- [Instructor] I'd like to talk about…the difference between constant…and read-only variables.…First thing to point out is that…constants are compile-time whereas…read-only variables are runtime constants.…Next is that a constant can be assigned…on declaration and that's it.…Whereas with read-only it can be…assigned on declaration or constructor.…A constant can only be a number,…boolean or string.…Whereas with read-only variable…it can be any data type.…
A constant is always static.…However, read-only variable is optionally static.…Now, let's go through some examples here.…Here in Visual Studio I'm in the program file…within the Prestige.Biz project.…And I'll start off by cleaning up…my using statements and get rid of…what I don't need.…I'll keep System because I know I'm…going to be using that.…But, let's go ahead and now create…a constant and we'll use the const…keyword to do so.…
It'll be an integer and we'll name…it ConstantVariable.…Assign it a value of 100.…Now, I will do a read-only one…and it will be static.…Specifying readonly and it'll be…
- 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.