I'm writing C# code, to be compiled with the command line compiler csc (not the IDE), that needs an object to represent a range of integers.
Happily, such a thing was introduced in C# 8.0: https://www.geeksforgeeks.org/range-structure-in-c-sharp-8-0
Unhappily, it's not working. To make sure I'm not misunderstanding how to use it, I just copied the sample program in its entirety from the above page, and tried compiling it:
C:\t>csc a.cs
Microsoft (R) Visual C# Compiler version 4.2.0-4.22281.5 (8d3180e5)
Copyright (C) Microsoft Corporation. All rights reserved.
a.cs(18,3): error CS0246: The type or namespace name 'Range' could not be found (are you missing a using directive or an assembly reference?)
a.cs(18,14): error CS0518: Predefined type 'System.Range' is not defined or imported
The sample code does specify using System so it doesn't seem to be a missing using directive.
Range was introduced in C# 8.0. As I understand it, this version of the language was introduced in an update to VS 2019. I'm using the compiler that was installed with VS 2022, so it should support 8.0.
What am I missing?
cscis the wrong compiler. Usedotnet buildinsteaddotnet buildcscis the C# compiler for .NET Framework, and .NET Framework does not support every new language feature, a notable one is theRangetype. Instead use the .NET Core (now named just .NET) compiler, i.edotnet build(and thedotnetCLI tool in general)just want to compile a single-file C# program,compile into what? Targeting which runtime, using which packages? In any case, what doesa.cscontain? There may be an actual error in the code. Or the compiler is complaining that you really didn't specify where to findSystem.Range, which is inSystem.Runtime