How to use out in c#7 with visual studio 2017

In c#7 you can use out keyword in new way , let's take an example

i need to get my name by out keyword in c#6 your code will be like this

public static void OldWay()
{
     string firstName;
     string lastName;
     MyName(out firstName, out lastName);

     Console.WriteLine($"My Name is :{ firstName} {lastName}  => Old way");
}

now in c#7 you don't need to define variables alone you just define it when you pass it to the method something like this

public static void CSharp7Way()
{
    MyName(out string firstName, out string lastName);

    Console.WriteLine($"My Name is :{ firstName} {lastName}  => c#7 way");
}

when you run you will see the magic and the same result :)

you can find the all code here

Go ahead and try it :)

Abdullah Zayed

Senior Software Developer

7 年

nice >>> go on man

回复
Maisam Abbas

Computer Instructor ~SST @FGEI(C/G) Schools System, Ministry of Defense, Pakistan

7 年

nice information. thanks

要查看或添加评论,请登录

Omar Maher的更多文章

社区洞察

其他会员也浏览了