'predefined type System.Range is not defined or imported
I'm using C# 8.0 (beta) in my UWP app with Visual Studio 2019 v16.0.2.
I was trying to use the new range operator of C# 8 : str[start..index] and then two errors showed up:
Predefined type
System.Rangeis not defined or imported
Predefined type
System.Indexis not defined or imported
But there is no such reference that I could use.
Visual Studio itself suggested me to use this feature. Is that the feature hasn't made available yet or what?
Solution 1:[1]
Indices and Ranges is a part of C# 8.0, which was released together with .NET Core 3.0 in September 2019. To use all of the C# 8.0 features, your target framework must be one of the following:
- .NET Standard 2.1
- .NET Core 3.0 and later
- .NET 5.0 and later
It is also possible to use C# 8.0 features on earlier versions of .NET, such as .NET Standard 2.0 and .NET Framework. To do this you need to override the default C# version on your project. However, Indices and Ranges is not officially supported on these earlier versions and will not work out-of-the-box. That being said, there is a possible workaround to make it work: https://www.meziantou.net/how-to-use-csharp-8-indices-and-ranges-in-dotnet-standard-2-0-and-dotn.htm
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
