Earlier I was getting the error:
Feature 'range operator' is not available in C# 7.3. Please use language version 8.0 or greater.
When I upgraded the project below error still remains:
Predefined type 'System.Range' is not defined or imported
Basically trying to test how can we retrieve a fragment of an array or string:
using System;
using System.Windows.Forms;
namespace TestRange
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
var story = "Testing C# 8";
Console.WriteLine(story[^6..^0]); // (last 6 chars)
}
}
}
Articles that I referred to but didn't help:
https://docs.microsoft.com/en-us/dotnet/api/system.range?view=netcore-3.1 https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-8.0/ranges https://docs.microsoft.com/en-us/dotnet/csharp/tutorials/ranges-indexes
https://www.infoworld.com/article/3532284/how-to-use-indices-and-ranges-in-csharp-80.html
https://www.codejourney.net/2019/02/csharp-8-slicing-indexes-ranges/
One related question: Array slices in C#