O'Reilly logo

Mastering Visual Studio 2017 by Kunal Chowdhury

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Local functions or nested functions

C# 7.0, which comes with Visual Studio 2017, allows you to write local functions or nested functions. The local function provides you with the ability to declare methods/functions inside an already defined methods body. It has the same capability as normal methods, but it will be scoped to the method block where they are declared.

In earlier versions of C#, we needed to write the method bodies separately and then we needed to call one method from the other. Here is the old way to write a method called by another method:

 public static Person GetBloggerDetails() { return new Person { FirstName = "Kunal", LastName = "Chowdhury", Blogs = GetBlogs() }; } private static List<string> GetBlogs() { return new List<string> ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required