Local Method Variable Capture with Lambda - CSharp Custom Type

CSharp examples for Custom Type:Local Method

Description

Local Method Variable Capture with Lambda

Demo Code

using System;/*from   www  .  ja  va2  s  .  com*/
using System.ComponentModel;
class LocalMethodVariableCapture2
{
   static void Main()
   {
      DateTime now = DateTime.UtcNow;
      int hour = now.Hour;
      if (hour > 5)
      {
         int minute = now.Minute;
         PrintHourAndMinute();
         void PrintHourAndMinute() =>
         Console.WriteLine($"hour = {hour}; j = {minute}");
      }
   }
}

Result


Related Tutorials