Create Local Method - CSharp Custom Type

CSharp examples for Custom Type:Local Method

Description

Create Local Method

Demo Code

using System;//ww  w .  jav a 2 s.c  o  m
using System.ComponentModel;
using System.Runtime.CompilerServices;
class LocalMethodIntro
{
   static void Main()
   {
      int x = 10;
      PrintAndIncrementX();
      PrintAndIncrementX();
      Console.WriteLine($"After calls, x = {x}");
      void PrintAndIncrementX()
      {
         Console.WriteLine($"x = {x}");
         x++;
      }
   }
}

Result


Related Tutorials