serving the solutions day and night

Pages

Monday, October 23, 2017

Visual Studio 2017 - C# 7.0 Features


1. Out Variables
static void Main(string[] args)
{
    string first = "M";
    string last = "K";
    string name = string.Empty; //have to pre-declare before using the out.
    GetName(first, last, out name);

    //In c# 7.0, you can declare in the variable line
    GetName(first, last, out string name1);
    GetName(first, last, out var name2); ////use var instead of string
}

static void GetName(string first, string last, out string name)
{
    name = first + " " + last;
}