C # class deconstruction

C # class deconstruction, Deconstruct method must be implemented in the class, and the void return type, and returns with the respective portions out parameter.

using System;
using System.Text;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            (int c, int d) = new Person();
            Console.WriteLine(c);
            Console.WriteLine(d);
        }
    }

    class Person
    {
        public void Deconstruct(out int a,out int b)
        {
            a = 122;
            b = 1;
        }
    }
}

 

Guess you like

Origin www.cnblogs.com/mlh1421/p/11516872.html