C# 8 comes with ranges, which allow you to take a slice of an array or string. Before, if you wanted to get only the first three numbers of an array, you had to iterate through the array and use a condition to find out which values you wanted to use. Let's take a look at an example:
using System;
namespace ConsoleApp6
{
class Program
{
static void Main(string[] args)
{
var numbers = new int[] { 1, 2, 3, 4, 5 };
foreach (var n in numbers)
{
if(numbers[3] == n) { break; }
Console.WriteLine(n);
}
Console.ReadKey();
}
}
}
With ranges, you can easily slice the array and take whatever value you want, as shown in the following code:
using System;
namespace ConsoleApp6
{
class Program
{
static void Main(string[] args)
{
var numbers = new int[] { 1, 2,...