Skip to Content
C# 7 and .NET Core 2.0 High Performance
book

C# 7 and .NET Core 2.0 High Performance

by Ovais Mehboob Ahmed Khan
April 2018
Intermediate to advanced
300 pages
7h 41m
English
Packt Publishing
Content preview from C# 7 and .NET Core 2.0 High Performance

Out variables

With C# 7.0, we can write cleaner code when using out variables. As we know, to use out variables, we have to first declare them. With the new language enhancement, we can now just write out as a prefix and specify the name of the variable that we need that value to be assigned to.

To clarify this concept, we will first see the traditional approach, which is shown as follows:

public void GetPerson() 
{ 
  int year; 
  int month; 
  int day; 
  GetPersonDOB(out year, out month, out day); 
} 
 
public void GetPersonDOB(out int year, out int month, out int day ) 
{ 
  year = 1980; 
  month = 11; 
  day = 3; 
} 

And here with C# 7.0, we can simplify the preceding GetPerson method, which is shown as follows:

public void GetPerson() { GetPersonDOB(out int year, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Professional C# 7 and .NET Core 2.0, 7th Edition

Professional C# 7 and .NET Core 2.0, 7th Edition

Christian Nagel
Pro ASP.NET Web API: HTTP Web Services in ASP.NET

Pro ASP.NET Web API: HTTP Web Services in ASP.NET

Tugberk Ugurlu, Alexander Zeitler, Ali Kheyrollahi
Enterprise Application Development with C# 9 and .NET 5

Enterprise Application Development with C# 9 and .NET 5

Ravindra Akella, Rishabh Verma, Arun Kumar Tamirisa, Suneel Kumar Kunani, Bhupesh Guptha Muthiyalu

Publisher Resources

ISBN: 9781788470049Supplemental Content