Learn how to avoid IndexOutOfRangeExceptions by keeping track of your indices in this video, and how to find and fix IndexOutOfRange errors with breakpoints and debug windows.
- [Instructor] Another common error in C# … as well as other programming languages … is the Index Out of Range Error … or the Index Out of Range Exception. … This error occurs when the program tries to access … an element in a collection using an index … that exceeds the collection's boundaries. … Typically, the first element in a collection … is located at index zero … and the last element is at index n minus one, … where n is the length or size of the collection. … If you attempt to access an element … outside of these boundaries, either with a negative index … or an index that is larger than the length minus one, … you will get an error because you are accessing something … that doesn't exist inside of the collection. … Let's take a look at an example of this in code. … In this program, we have an array called numbers … and we put five items into it. … Then we print out the item at index zero, … index negative one, and index five. … Let's run the program and see what happens. … And so the item at index zero is going to be 10 …
Author
Released
4/23/2019- Debugging defined
- Working with breakpoints
- Inspecting values of variables
- Defensive programming
- Common C# errors
- Debugging challenges
Skill Level Beginner
Duration
Views
Related Courses
-
Object Oriented Programming with C#
with Anton Delsink4h 7m Intermediate -
Learning C#
with Alexander Zanfir3h 4m Beginner -
Nail Your C# Developer Interview
with Reynald Adolphe1h 17m Beginner -
C# Design Patterns: Part 1 (2016)
with Reynald Adolphe1h 22m Intermediate
-
Introduction
-
Debugging in C#45s
-
-
1. Basics of Debugging
-
What is debugging?2m 1s
-
What is a breakpoint?5m 59s
-
Execution in debug mode3m 40s
-
The debugging process2m 11s
-
-
2. More Debugging Tips and Tricks
-
Covering edge cases3m 57s
-
Defensive programming3m 13s
-
Side effects3m 57s
-
-
3. Common Errors in C#
-
NullReferenceException4m 50s
-
IndexOutOfRangeException6m 10s
-
Logical errors5m 56s
-
-
4. Practice Debugging C# Programs
-
Logical code challenge3m 23s
-
Conclusion
-
Next steps43s
-
- 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: IndexOutOfRangeException