c# – Bob Thompson http://www.drbob.17after.com My musings Thu, 26 Jul 2018 12:02:13 +0000 en-US hourly 1 https://wordpress.org/?v=7.0 C# 8 Ranges and Recursive Patterns http://www.drbob.17after.com/2018/07/26/c-8-ranges-and-recursive-patterns/ Thu, 26 Jul 2018 12:02:13 +0000 http://www.drbob.17after.com/?p=1119 Source: InfoQ

This article discusses two features proposed for C# 8: Ranges and Recursive Patterns. Both of these belong to the category of Code Simplification. The article explains these in detail with many examples and how these features can help you to write better code.

Key Takeaways

  • C# 8 Adds Ranges and Recursive Patterns
  • Ranges easily define a sequence of data, replacing the Enumberable.Range()
  • Recursive Patterns brings an F#-like construct to C#
  • Recursive Patterns is an awesome feature, it giving you the flexibility to testing the data against a sequence of conditions and performing further computations based on the condition met.
  • Ranges is very useful to generate sequences of numbers in the form of a collection or a list.

Ranges easily define a sequence of data. It is a replacement for Enumerable.Range() except it defines the start and stop points rather than start and count and it helps you to write more readable code.

Recursive Patterns matching is a very powerful feature, which allows code to be written more elegantly, mainly when used together with recursion. The Recursive Patterns consists of multiple sub-patterns like as Positional Patterns, e.g.,var isBassam = user is Employee ("Bassam",_), Property Patterns, e.g.,p is Employee {Name is "Mais"}, Var Pattern, Discard Pattern (‘_’),and so forth.

 

Read the entire article at InfoQ.

]]>
What is new in C#7.1 & C#7.2 http://www.drbob.17after.com/2018/02/09/what-is-new-in-c7-1-c7-2/ Fri, 09 Feb 2018 18:17:12 +0000 http://www.drbob.17after.com/?p=607 This article describes new features of C# 7.1, C# 7.2 and lists some of the planned features of C# 8. Here’s a quick overview of what the article covers:

  1. How to select C# language version in visual studio (C#7.1/C#7.2)?
  2. New features in C# 7.1
    • Inferred tuple element names
    • Async main
    • Default literal expressions
  3. New features in C# 7.2
    • Private protected access modifier
    • Non-trailing named arguments
    • Leading underscores in numeric literals
    • Reference semantics with value types
  4. A Preview of C# 8

Get the details at Code Project

]]>
Consume RESTful API in C# http://www.drbob.17after.com/2018/02/08/605/ Thu, 08 Feb 2018 17:59:04 +0000 http://www.drbob.17after.com/?p=605 If you are involved in much web development, you will eventually need to work with web services or web APIs. This is a great article that summarizes a few of the different ways you can write C# code to work with these services. It covers the following methods to consume a RESTful API in C#:

  • HttpWebRequest/Response class
  • WebClient class
  • HttpClient class
  • RestSharp NuGet package
  • ServiceStack Http Utils

Each of them have their own pros and cons, and article gives a good overview of them. Find out more at RESTful API in C#.

]]>