Use C# 7 syntax and new System.ValueTuple type - CSharp Language Basics

CSharp examples for Language Basics:Tuple

Description

Use C# 7 syntax and new System.ValueTuple type


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

class Program
{
    static void Main(string[] args)
    {
        var p3 = new Person();
        WriteLine($"{p3.Name} was instantiated at  {p3.Instantiated:hh:mm:ss} on {p3.Instantiated:dddd, d MMMM  yyyy}");

        var fruit7 = p3.GetFruitCS7();
        WriteLine($"{fruit7.Name}, {fruit7.Number} there are.");
    }
}
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