I'm in the midst of fiddling around with some new C# code I learned. I literally started learning today so this is a very newb question.
Basically, I learned to put a $ in front of a string to enable formatting using curly braces and variable names from CodeCademy. In the lesson I learned to use C#'s $ marker like this:
using System;
namespace StoryTime
{
class Program
{
static void Main(string[] args)
{
// Declare the variables
string beginning = "Once upon a time,";
string middle = "The kid climbed a tree";
string end = "Everyone lived happily ever after.";
// Interpolate the string and the variables
string story = $"{beginning} {middle}. {end}";
// Print the story to the console
Console.WriteLine(story);
}
}
}
Now I'm over in Visual Studio Code writing my own code to practice. Unfortunately, when I used the $ marker, my csc compiler told me:
text.cs(13,28): error CS1056: Unexpected character '$'
Here is the code that caused the error:
namespace Textperiment
{
class Program
{
static void Main()
{
string a = "alphabet";
string b = "learn";
string c = "easy";
string d = $"I {b}ed the {a} in 1st grade. It was {c}.";
Console.WriteLine(d);
Console.WriteLine(d.ToUpper);
}
}
My expected output is "I learned the alphabet in 1st grade. It was easy." $ initiates string interpolation, the variables fill it in. But instead I get an error.
I've tried Googling the error and reading the pages that show up. They aren't promising as they suggest installing stuff, which seems overkill for what looks like a syntax error.
The code did work in Visual Studio 2019 so I believe the error is coming from using csc.exe as my compiler, which "This compiler is provided as part of the Microsoft (R) .NET Framework, but only supports language versions up to C# 5, which is no longer the latest version."
In which case it does seem I have to upgrade, but to what?
What does a good job of replacing csc.exe in the terminal? I just wanna compile executables and run 'em since I'm happy writing code in Visual Studio Code.