public static async Task Main(string[] args) { Console.WriteLine("\n\t NullCoalescing Demo\n\n"); var nc = new NullCoalescing(); nc.NullCoalescingExample(); var indexAndRange = new IndicesAndRanges(); indexAndRange.IndexAndRange(); Company company = new Company(); Console.WriteLine("\n\t NullCoalescing Demo Ends Here\n\n"); Console.WriteLine("\n\t Press Any Key....Proceed to Next Demo\n\n"); Console.ReadLine(); Console.ReadLine(); //Lets demonstrate Using declaration Console.WriteLine("\n\n Showing using declaration \n\n"); try { //creating new resource using var resource = new UsingDeclaration(); Console.WriteLine("Using resource1..."); if (true) { using var resource2 = new UsingDeclaration(); Console.WriteLine("Using resource2..."); // Asynchronous disposable demo await using var resource3 = new UsingDeclaration(); Console.WriteLine("Using resource3..."); } } catch (Exception e) { Console.WriteLine(e); throw; } Console.WriteLine("\n\n \tDemonstration of Switch Expression Functionality\n\n"); Console.WriteLine("\n\t Press Any Key....Proceed to Next Demo\n\n"); Console.ReadLine(); }
static private IEnumerable <Topic> GetTopicsForWhatsNewCSharp() { Debugger.Break(); var topics = new List <Topic>(); // C# 7 - https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-7#throw-expressions topics.Add(new Topic("Throw Expressions")); ThrowExp.Run(); Debugger.Break(); // C# 7 - https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-7#tuples" topics.Add(new Topic("Tuples")); Tuples.Run(); Debugger.Break(); // C# 7 - https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-7#pattern-matching topics.Add(new Topic("Pattern Matching")); PatternMatchingIs.Run(); PatternMatchingSwitch.Run(); Debugger.Break(); // C# 7 - https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-7#discards topics.Add(new Topic("Discards")); Discards.Run(); Debugger.Break(); // C# 7 - https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-7#local-functions // C# 8 - https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-8#static-local-functions topics.Add(new Topic("Local Functions & Static Local Functions.")); LocalFunctions.Run(); Debugger.Break(); // C# 7.1 - https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-7-1#async-main topics.Add(new Topic("Async Main")); Debugger.Break(); // C# 7.1 - https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-7-1#default-literal-expressions topics.Add(new Topic("Default Literal Expressions")); DefaultLiteralExpressions.Run(); Debugger.Break(); // C# 7.1 - https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-7-1#inferred-tuple-element-names topics.Add(new Topic("Inferred Tuple Property Names")); InferredTuple.Run(); Debugger.Break(); // C# 7.2 - https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-7-2#safe-efficient-code-enhancements // https://docs.microsoft.com/en-us/dotnet/csharp/write-safe-efficient-code topics.Add(new Topic("Safe Code Enhancements")); Debugger.Break(); // C# 7.2 - https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-7-2#private-protected-access-modifier topics.Add(new Topic("Private Protected modifier")); PrivateProtected.Run(); Debugger.Break(); // C# 7.3 - https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-7-3 topics.Add(new Topic("C# 7.3 Improvements")); Debugger.Break(); // C# 8.0 - https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-8#default-interface-methods topics.Add(new Topic("Interface Implementation")); InterfaceImplementation.Run(); Debugger.Break(); // C# 8.0 - https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-8#more-patterns-in-more-places topics.Add(new Topic("Switch Expressions")); SwitchExpressions.Run(); Debugger.Break(); // C# 8.0 - https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-8#using-declarations topics.Add(new Topic("Using Declaration")); UsingDeclaration.Run(); Debugger.Break(); // C# 8.0 - https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-8#using-declarations topics.Add(new Topic("Nullable Refernce types")); NullableRefTypes.Run(); Debugger.Break(); // C# 8.0 - https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-8#asynchronous-streams topics.Add(new Topic("Async Streams")); AsyncStream.Run(); Debugger.Break(); // C# 8.0 - https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-8#null-coalescing-assignment topics.Add(new Topic("Null Coalescing Assignment")); NullCoalescing.Run(); Debugger.Break(); // C# 8.0 - https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-8#indices-and-ranges topics.Add(new Topic("Indexes and Ranges")); IndexesAndRanges.Run(); Debugger.Break(); return(topics); }