Reaz Haq
Released just a few weeks ago (March 7, 2017, along with new version of VS), C# 7 brings some new and interesting features; like tuple, pattern matching, etc. In this talk, I shall ‘show and tell’ some of these new features [with code examples], as well as few interesting ones that didn’t make the final cut. Sample code at https://github.com/reazhaq/CSharp7
Geek and Independent Consultant with over 20 years of experiance
/////// DURING THIS TALK AT AUSTIN .NET USER GROUP
/////// SOMEONE HAD ASKED WHAT OTHER WAYS TO DECLARE RETURN VARIABLE INSTEAD OF ‘var’
/////// HERE ARE FEW EXAMPLES
//// ValueTuple is one simple way
ValueTuple blah = CalculateSumAndCount3(someNumbers);
Console.WriteLine($”blah.Item1 = {blah.Item1}”);
//// (int, int) is another choice
(int, int) blah2 = CalculateSumAndCount3(someNumbers);
Console.WriteLine($”blah2.Item1 = {blah2.Item1}”);
//// let’s say we don’t need the 2nd part of the tuple; use wildcard
var (s2, _) = CalculateSumAndCount3(someNumbers);
Console.WriteLine($”var (s2, _) -> s2={s2}”);
////// another correction regarding out variable and wildcard
/////// FOR WILDCARD USE UNDERSCORE NOT *
if (int.TryParse(someNumberAsAString, out _))
Console.WriteLine($”\”{someNumberAsAString}\” was parsed -> …”);
Sample code (GitHub) have been updated
https://github.com/reazhaq/CSharp7
Updated GitHub with correct wildcard (out variable) code; updated tuple code with additional declaration formats.
Made some correction to the sample code; like wildcard out variable, etc. At the time of this talk, I used ‘*’; but it got implemented as ‘_’. Style is similar when one needs to ignore part of tuple.