Create Tuple object from object - CSharp Language Basics

CSharp examples for Language Basics:Tuple

Description

Create Tuple object from object


using static System.Console;
using System;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        var p1 = new Person();
        var thing2 = (p1.Name, p1.Children.Count);
        WriteLine($"{thing2.Name} has {thing2.Count} children.");

    }
}
public class Person : object
{
    public string Name;
    public DateTime DateOfBirth;
    public List<Person> Children = new List<Person>();
    public readonly DateTime Instantiated;

    public const string Species = "Programmer";


    public readonly string HomePlanet = "Earth";


    public Person()
    {
        // set default values for fields
        // including read-only fields
        Name = "Unknown";
        Instantiated = DateTime.Now;
    }

    public Person(string initialName)
    {
        Name = initialName;
        Instantiated = DateTime.Now;
    }
    // the new C# 7 syntax and new System.ValueTuple type
    public (string Name, int Number) GetFruitCS7()
    {
        return (Name: "Apples", Number: 5);
    }
}

Related Tutorials