DateTime Deconstruction with Tuple - CSharp Language Basics

CSharp examples for Language Basics:Tuple

Description

DateTime Deconstruction with Tuple

Demo Code

using System;//w w  w .j a  va2 s  . c o  m
using System.ComponentModel;
static class DateTimeDeconstruction
{
   static void Deconstruct(
   this DateTime dateTime,
   out int year, out int month, out int day) =>
   (year, month, day) = (dateTime.Year, dateTime.Month, dateTime.Day);
   static void Main()
   {
      DateTime now = DateTime.UtcNow;
      var (year, month, day) = now;
      Console.WriteLine($"{year:0000}-{month:00}-{day:00}");
   }
}

Result


Related Tutorials