Local Functions

Create methods within methods.

We'll cover the following

C# 7.0. and later includes local functions. These are private methods that we can define within other methods.

Local functions aid code-readability. If we need several methods that are called by only one method, then it would be much clearer for other developers if we make these methods local to the calling method. This way, it’s impossible to mistakenly call these methods elsewhere in the class.

The way we create and use local functions is similar to how we work with regular methods. There are a couple of differences, however, and they’ll be covered in this lesson.

A method that contains other methods

Get hands-on with 1200+ tech skills courses.