Assign two value in one statement with Tuple - CSharp Language Basics

CSharp examples for Language Basics:Tuple

Description

Assign two value in one statement with Tuple

Demo Code

using System;//from w ww.ja  v  a2 s  .  c om
using System.ComponentModel;
public sealed class Point
{
   public double X { get; }
   public double Y { get; }
   public Point(double x, double y) => (X, Y) = (x, y);
   public void Deconstruct(out double x, out double y) => (x, y) = (X, Y);
}
class PointDeconstruction
{
   static void Main()
   {
      var point = new Point(1.5, 20);
      var (x, y) = point;
      Console.WriteLine($"x = {x}");
      Console.WriteLine($"y = {y}");
   }
}

Result


Related Tutorials