Intellisense suggested the use of ‘Index from End’ operator for my small test program. I tested the same code in the Fire IDE (Hydrogene) and it unfortunately generates an ‘NullReferenceException’ error. But the same exact code does NOT generate an error in the Water IDE. I’m not sure why … but thanks for looking!
OK, I think I figured out partially why this is occurring. When I run the programs using top-level statements - the errors occur in both Fire and Water IDE’s. So it appears the partial ‘solution’ is NOT to use top-level statements:
Here’s a simple test case, I’ve tested it out with Fire IDE (2903) running various versions of .Net (from .NetCore to .Net8.0). This version work as is. Just comment out the boiler template code to see the error described above.
namespace IndexFromEnd_CS
{
static class Program
{
public static Int32 Main(string[] args)
{
var numbers = new int[]{2, 6, 1, 6, 19};
writeLn("Hello");
//var firstFromEnd = numbers[numbers.Length - 1];
var firstFromEnd = numbers[^1];
//var secondFromEnd = numbers[numbers.Length - 2];
var secondFromEnd = numbers[^2];
writeLn(firstFromEnd);
writeLn(secondFromEnd);
return 0;
}
}
}