For newbies, It would be very nice to see some explanations or note on $" (in Performing Operations on Source Elements section)
⚠Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
Hi @Vespiyanus, thank you for raising this concern. Yes, I can see how it might be confusing to newbies. All of a sudden new and unfamiliar syntax is being used without any details about its usage.
I've added the "up-for-grabs" label on this issue, so that anyone could work on it before we have a chance to. To answer the ask, the $" is used for formatting strings, and is called string interpolation.
What it does, is format expressions within the string. It tells the C# compiler that the string should evaluate the expressions and then concatenate the pieces together.
double[] radii = { 1, 2, 3 };
IEnumerable<string> query =
from rad in radii
select $"Area = {rad * rad * Math.PI:F2}";
This is essentially shorthand for this "Area = " + (rad * rad * Math.PI).ToString("F2")
The query could then be iterated on, and it's just a string collection with the following values:
"Area = 3.14",
"Area = 12.57",
"Area = 28.27"
I'd like to take a crack at refactoring this particular section to provide a bit more clarity for newer readers, if that's alright.
Hi @jmarkman - absolutely. Thank you
Most helpful comment
I'd like to take a crack at refactoring this particular section to provide a bit more clarity for newer readers, if that's alright.