String interpolation - what does the @ sign inside the curly braces do?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
19
down vote

favorite












Consider:



string newline = "rn";

Console.WriteLine($"Hello without atnewlinehow are you?");
Console.WriteLine($"Hello with at@newlinehow are you?");


The output of both lines is identical. The newline is always printed as a newline.



Hello without at
how are you?
Hello with at
how are you?


So when do I need the at sign inside the curly braces?







share|improve this question


















  • 1




    Possible duplicate: stackoverflow.com/questions/6134547/…
    – Keyur Ramoliya
    Aug 31 at 8:59






  • 5




    This one is related
    – Mong Zhu
    Aug 31 at 9:00






  • 7




    @KeyurRamoliya: It's definitely not a duplicate of that. That's about verbatim string literals. This isn't one of those. It's using @ with an identifier, which is typically used with keywords, e.g. @this as the name of the first parameter in an extension method.
    – Jon Skeet
    Aug 31 at 9:00










  • @KeyurRamoliya I don't think that's a correct duplicate. HimBromBeere's answer is correct.
    – Sweeper
    Aug 31 at 9:01










  • Reference for verbatim string here.
    – Tetsuya Yamamoto
    Aug 31 at 9:01














up vote
19
down vote

favorite












Consider:



string newline = "rn";

Console.WriteLine($"Hello without atnewlinehow are you?");
Console.WriteLine($"Hello with at@newlinehow are you?");


The output of both lines is identical. The newline is always printed as a newline.



Hello without at
how are you?
Hello with at
how are you?


So when do I need the at sign inside the curly braces?







share|improve this question


















  • 1




    Possible duplicate: stackoverflow.com/questions/6134547/…
    – Keyur Ramoliya
    Aug 31 at 8:59






  • 5




    This one is related
    – Mong Zhu
    Aug 31 at 9:00






  • 7




    @KeyurRamoliya: It's definitely not a duplicate of that. That's about verbatim string literals. This isn't one of those. It's using @ with an identifier, which is typically used with keywords, e.g. @this as the name of the first parameter in an extension method.
    – Jon Skeet
    Aug 31 at 9:00










  • @KeyurRamoliya I don't think that's a correct duplicate. HimBromBeere's answer is correct.
    – Sweeper
    Aug 31 at 9:01










  • Reference for verbatim string here.
    – Tetsuya Yamamoto
    Aug 31 at 9:01












up vote
19
down vote

favorite









up vote
19
down vote

favorite











Consider:



string newline = "rn";

Console.WriteLine($"Hello without atnewlinehow are you?");
Console.WriteLine($"Hello with at@newlinehow are you?");


The output of both lines is identical. The newline is always printed as a newline.



Hello without at
how are you?
Hello with at
how are you?


So when do I need the at sign inside the curly braces?







share|improve this question














Consider:



string newline = "rn";

Console.WriteLine($"Hello without atnewlinehow are you?");
Console.WriteLine($"Hello with at@newlinehow are you?");


The output of both lines is identical. The newline is always printed as a newline.



Hello without at
how are you?
Hello with at
how are you?


So when do I need the at sign inside the curly braces?









share|improve this question













share|improve this question




share|improve this question








edited Aug 31 at 13:52









Peter Mortensen

12.9k1983111




12.9k1983111










asked Aug 31 at 8:57









Thomas

1,0001833




1,0001833







  • 1




    Possible duplicate: stackoverflow.com/questions/6134547/…
    – Keyur Ramoliya
    Aug 31 at 8:59






  • 5




    This one is related
    – Mong Zhu
    Aug 31 at 9:00






  • 7




    @KeyurRamoliya: It's definitely not a duplicate of that. That's about verbatim string literals. This isn't one of those. It's using @ with an identifier, which is typically used with keywords, e.g. @this as the name of the first parameter in an extension method.
    – Jon Skeet
    Aug 31 at 9:00










  • @KeyurRamoliya I don't think that's a correct duplicate. HimBromBeere's answer is correct.
    – Sweeper
    Aug 31 at 9:01










  • Reference for verbatim string here.
    – Tetsuya Yamamoto
    Aug 31 at 9:01












  • 1




    Possible duplicate: stackoverflow.com/questions/6134547/…
    – Keyur Ramoliya
    Aug 31 at 8:59






  • 5




    This one is related
    – Mong Zhu
    Aug 31 at 9:00






  • 7




    @KeyurRamoliya: It's definitely not a duplicate of that. That's about verbatim string literals. This isn't one of those. It's using @ with an identifier, which is typically used with keywords, e.g. @this as the name of the first parameter in an extension method.
    – Jon Skeet
    Aug 31 at 9:00










  • @KeyurRamoliya I don't think that's a correct duplicate. HimBromBeere's answer is correct.
    – Sweeper
    Aug 31 at 9:01










  • Reference for verbatim string here.
    – Tetsuya Yamamoto
    Aug 31 at 9:01







1




1




Possible duplicate: stackoverflow.com/questions/6134547/…
– Keyur Ramoliya
Aug 31 at 8:59




Possible duplicate: stackoverflow.com/questions/6134547/…
– Keyur Ramoliya
Aug 31 at 8:59




5




5




This one is related
– Mong Zhu
Aug 31 at 9:00




This one is related
– Mong Zhu
Aug 31 at 9:00




7




7




@KeyurRamoliya: It's definitely not a duplicate of that. That's about verbatim string literals. This isn't one of those. It's using @ with an identifier, which is typically used with keywords, e.g. @this as the name of the first parameter in an extension method.
– Jon Skeet
Aug 31 at 9:00




@KeyurRamoliya: It's definitely not a duplicate of that. That's about verbatim string literals. This isn't one of those. It's using @ with an identifier, which is typically used with keywords, e.g. @this as the name of the first parameter in an extension method.
– Jon Skeet
Aug 31 at 9:00












@KeyurRamoliya I don't think that's a correct duplicate. HimBromBeere's answer is correct.
– Sweeper
Aug 31 at 9:01




@KeyurRamoliya I don't think that's a correct duplicate. HimBromBeere's answer is correct.
– Sweeper
Aug 31 at 9:01












Reference for verbatim string here.
– Tetsuya Yamamoto
Aug 31 at 9:01




Reference for verbatim string here.
– Tetsuya Yamamoto
Aug 31 at 9:01












2 Answers
2






active

oldest

votes

















up vote
26
down vote



accepted










$"Hello myValue " is an interpolated string which was introduced in C#6. In your case this is equivalent to a call to String.Format("Hello 0", myValue).



The verbatim (@) is needed when your variable has the same name as a keyword, which, as far as I know, newline is not. However the following would cause a compiler-error:



String.Format("Hello 0", if)


whilst this won´t:



String.Format("Hello 0", @if)


Here the verbatim tells the compiler that if is the name of a variable, not the if-keyword.



So you don´t need the verbatim in your case, because newline is not a keyword. Or in other words your code is equivalent to this:



Console.WriteLine("Hello with at0how are you?", @newline);


which is a valid (even though redundant) use of the verbatim.



For further information refer to the documentation about string-interpolation.






share|improve this answer


















  • 1




    $ is not really a shortcut for String.Format it basically returns a FormattableString which in many ways differs from String.Format
    – Mateusz
    Aug 31 at 9:09










  • @Mateusz Doesn´t String.Format return an FormatableString also?
    – HimBromBeere
    Aug 31 at 9:10










  • Not quite the same, $ can return a string already processed, FormattableString which then can be used to process it on how you want/need it to and IFormattable which is the only one that really relates to String.Format method but it's not a shortcut, more like a long road to format.
    – Mateusz
    Aug 31 at 9:13






  • 1




    $"Hello myValue" is in fact also a shortcut to string.Format since the compiler will only use the FormattableString if the only target for the expression is a FormattableString. So the compiler will reformat this directly to a string.Format call.
    – Lasse Vågsæther Karlsen
    Aug 31 at 9:14






  • 1




    It is also worth to mention about interoperability between different languages. Keyword in one language is not necessarily the keyword in the second.
    – Karol
    Sep 1 at 12:11

















up vote
13
down vote













It's a redundant verbatim prefix. From the C# specification:




The prefix "@" enables the use of keywords as identifiers, which is useful when interfacing with other programming languages. The character @ is not actually part of the identifier, so the identifier might be seen in other languages as a normal identifier, without the prefix. An identifier with an @ prefix is called a verbatim identifier. Use of the @ prefix for identifiers that are not keywords is permitted, but strongly discouraged as a matter of style.




A use case would be if you would want to write a function like this:



private void print(string @string) => Console.WriteLine(@string);


Normally you would not be able to name an identifier string because it is a reserved keyword. The @ prefix enables you to do so.






share|improve this answer


















  • 4




    Important part is "The character @ is not actually part of the identifier" because that explains why it compiles even if the variable doesn't have it.
    – Tim Schmelter
    Aug 31 at 9:08







  • 4




    Another part that I find important is "Use of the @ prefix for identifiers that are not keywords is permitted, but strongly discouraged as a matter of style." So @newline is tolerated but misleading/confusing.
    – Jeppe Stig Nielsen
    Aug 31 at 9:40










  • I note that your example does not match the text you've quoted from the specification, and that this is a very poor use case. The purpose of this feature is not to allow you to make a formal parameter called @string because that would be a bizarre thing to do. The purpose of the feature is to allow you to, say, extend a third-party class written in a non-C# language that has a virtual member called string. You need to be able to say class D : ThirdParty public override void @string() ... . That would be a by-design use case.
    – Eric Lippert
    Aug 31 at 21:13











Your Answer





StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52111891%2fstring-interpolation-what-does-the-sign-inside-the-curly-braces-do%23new-answer', 'question_page');

);

Post as a guest






























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
26
down vote



accepted










$"Hello myValue " is an interpolated string which was introduced in C#6. In your case this is equivalent to a call to String.Format("Hello 0", myValue).



The verbatim (@) is needed when your variable has the same name as a keyword, which, as far as I know, newline is not. However the following would cause a compiler-error:



String.Format("Hello 0", if)


whilst this won´t:



String.Format("Hello 0", @if)


Here the verbatim tells the compiler that if is the name of a variable, not the if-keyword.



So you don´t need the verbatim in your case, because newline is not a keyword. Or in other words your code is equivalent to this:



Console.WriteLine("Hello with at0how are you?", @newline);


which is a valid (even though redundant) use of the verbatim.



For further information refer to the documentation about string-interpolation.






share|improve this answer


















  • 1




    $ is not really a shortcut for String.Format it basically returns a FormattableString which in many ways differs from String.Format
    – Mateusz
    Aug 31 at 9:09










  • @Mateusz Doesn´t String.Format return an FormatableString also?
    – HimBromBeere
    Aug 31 at 9:10










  • Not quite the same, $ can return a string already processed, FormattableString which then can be used to process it on how you want/need it to and IFormattable which is the only one that really relates to String.Format method but it's not a shortcut, more like a long road to format.
    – Mateusz
    Aug 31 at 9:13






  • 1




    $"Hello myValue" is in fact also a shortcut to string.Format since the compiler will only use the FormattableString if the only target for the expression is a FormattableString. So the compiler will reformat this directly to a string.Format call.
    – Lasse Vågsæther Karlsen
    Aug 31 at 9:14






  • 1




    It is also worth to mention about interoperability between different languages. Keyword in one language is not necessarily the keyword in the second.
    – Karol
    Sep 1 at 12:11














up vote
26
down vote



accepted










$"Hello myValue " is an interpolated string which was introduced in C#6. In your case this is equivalent to a call to String.Format("Hello 0", myValue).



The verbatim (@) is needed when your variable has the same name as a keyword, which, as far as I know, newline is not. However the following would cause a compiler-error:



String.Format("Hello 0", if)


whilst this won´t:



String.Format("Hello 0", @if)


Here the verbatim tells the compiler that if is the name of a variable, not the if-keyword.



So you don´t need the verbatim in your case, because newline is not a keyword. Or in other words your code is equivalent to this:



Console.WriteLine("Hello with at0how are you?", @newline);


which is a valid (even though redundant) use of the verbatim.



For further information refer to the documentation about string-interpolation.






share|improve this answer


















  • 1




    $ is not really a shortcut for String.Format it basically returns a FormattableString which in many ways differs from String.Format
    – Mateusz
    Aug 31 at 9:09










  • @Mateusz Doesn´t String.Format return an FormatableString also?
    – HimBromBeere
    Aug 31 at 9:10










  • Not quite the same, $ can return a string already processed, FormattableString which then can be used to process it on how you want/need it to and IFormattable which is the only one that really relates to String.Format method but it's not a shortcut, more like a long road to format.
    – Mateusz
    Aug 31 at 9:13






  • 1




    $"Hello myValue" is in fact also a shortcut to string.Format since the compiler will only use the FormattableString if the only target for the expression is a FormattableString. So the compiler will reformat this directly to a string.Format call.
    – Lasse Vågsæther Karlsen
    Aug 31 at 9:14






  • 1




    It is also worth to mention about interoperability between different languages. Keyword in one language is not necessarily the keyword in the second.
    – Karol
    Sep 1 at 12:11












up vote
26
down vote



accepted







up vote
26
down vote



accepted






$"Hello myValue " is an interpolated string which was introduced in C#6. In your case this is equivalent to a call to String.Format("Hello 0", myValue).



The verbatim (@) is needed when your variable has the same name as a keyword, which, as far as I know, newline is not. However the following would cause a compiler-error:



String.Format("Hello 0", if)


whilst this won´t:



String.Format("Hello 0", @if)


Here the verbatim tells the compiler that if is the name of a variable, not the if-keyword.



So you don´t need the verbatim in your case, because newline is not a keyword. Or in other words your code is equivalent to this:



Console.WriteLine("Hello with at0how are you?", @newline);


which is a valid (even though redundant) use of the verbatim.



For further information refer to the documentation about string-interpolation.






share|improve this answer














$"Hello myValue " is an interpolated string which was introduced in C#6. In your case this is equivalent to a call to String.Format("Hello 0", myValue).



The verbatim (@) is needed when your variable has the same name as a keyword, which, as far as I know, newline is not. However the following would cause a compiler-error:



String.Format("Hello 0", if)


whilst this won´t:



String.Format("Hello 0", @if)


Here the verbatim tells the compiler that if is the name of a variable, not the if-keyword.



So you don´t need the verbatim in your case, because newline is not a keyword. Or in other words your code is equivalent to this:



Console.WriteLine("Hello with at0how are you?", @newline);


which is a valid (even though redundant) use of the verbatim.



For further information refer to the documentation about string-interpolation.







share|improve this answer














share|improve this answer



share|improve this answer








edited Sep 4 at 6:41

























answered Aug 31 at 8:59









HimBromBeere

21.7k33156




21.7k33156







  • 1




    $ is not really a shortcut for String.Format it basically returns a FormattableString which in many ways differs from String.Format
    – Mateusz
    Aug 31 at 9:09










  • @Mateusz Doesn´t String.Format return an FormatableString also?
    – HimBromBeere
    Aug 31 at 9:10










  • Not quite the same, $ can return a string already processed, FormattableString which then can be used to process it on how you want/need it to and IFormattable which is the only one that really relates to String.Format method but it's not a shortcut, more like a long road to format.
    – Mateusz
    Aug 31 at 9:13






  • 1




    $"Hello myValue" is in fact also a shortcut to string.Format since the compiler will only use the FormattableString if the only target for the expression is a FormattableString. So the compiler will reformat this directly to a string.Format call.
    – Lasse Vågsæther Karlsen
    Aug 31 at 9:14






  • 1




    It is also worth to mention about interoperability between different languages. Keyword in one language is not necessarily the keyword in the second.
    – Karol
    Sep 1 at 12:11












  • 1




    $ is not really a shortcut for String.Format it basically returns a FormattableString which in many ways differs from String.Format
    – Mateusz
    Aug 31 at 9:09










  • @Mateusz Doesn´t String.Format return an FormatableString also?
    – HimBromBeere
    Aug 31 at 9:10










  • Not quite the same, $ can return a string already processed, FormattableString which then can be used to process it on how you want/need it to and IFormattable which is the only one that really relates to String.Format method but it's not a shortcut, more like a long road to format.
    – Mateusz
    Aug 31 at 9:13






  • 1




    $"Hello myValue" is in fact also a shortcut to string.Format since the compiler will only use the FormattableString if the only target for the expression is a FormattableString. So the compiler will reformat this directly to a string.Format call.
    – Lasse Vågsæther Karlsen
    Aug 31 at 9:14






  • 1




    It is also worth to mention about interoperability between different languages. Keyword in one language is not necessarily the keyword in the second.
    – Karol
    Sep 1 at 12:11







1




1




$ is not really a shortcut for String.Format it basically returns a FormattableString which in many ways differs from String.Format
– Mateusz
Aug 31 at 9:09




$ is not really a shortcut for String.Format it basically returns a FormattableString which in many ways differs from String.Format
– Mateusz
Aug 31 at 9:09












@Mateusz Doesn´t String.Format return an FormatableString also?
– HimBromBeere
Aug 31 at 9:10




@Mateusz Doesn´t String.Format return an FormatableString also?
– HimBromBeere
Aug 31 at 9:10












Not quite the same, $ can return a string already processed, FormattableString which then can be used to process it on how you want/need it to and IFormattable which is the only one that really relates to String.Format method but it's not a shortcut, more like a long road to format.
– Mateusz
Aug 31 at 9:13




Not quite the same, $ can return a string already processed, FormattableString which then can be used to process it on how you want/need it to and IFormattable which is the only one that really relates to String.Format method but it's not a shortcut, more like a long road to format.
– Mateusz
Aug 31 at 9:13




1




1




$"Hello myValue" is in fact also a shortcut to string.Format since the compiler will only use the FormattableString if the only target for the expression is a FormattableString. So the compiler will reformat this directly to a string.Format call.
– Lasse Vågsæther Karlsen
Aug 31 at 9:14




$"Hello myValue" is in fact also a shortcut to string.Format since the compiler will only use the FormattableString if the only target for the expression is a FormattableString. So the compiler will reformat this directly to a string.Format call.
– Lasse Vågsæther Karlsen
Aug 31 at 9:14




1




1




It is also worth to mention about interoperability between different languages. Keyword in one language is not necessarily the keyword in the second.
– Karol
Sep 1 at 12:11




It is also worth to mention about interoperability between different languages. Keyword in one language is not necessarily the keyword in the second.
– Karol
Sep 1 at 12:11












up vote
13
down vote













It's a redundant verbatim prefix. From the C# specification:




The prefix "@" enables the use of keywords as identifiers, which is useful when interfacing with other programming languages. The character @ is not actually part of the identifier, so the identifier might be seen in other languages as a normal identifier, without the prefix. An identifier with an @ prefix is called a verbatim identifier. Use of the @ prefix for identifiers that are not keywords is permitted, but strongly discouraged as a matter of style.




A use case would be if you would want to write a function like this:



private void print(string @string) => Console.WriteLine(@string);


Normally you would not be able to name an identifier string because it is a reserved keyword. The @ prefix enables you to do so.






share|improve this answer


















  • 4




    Important part is "The character @ is not actually part of the identifier" because that explains why it compiles even if the variable doesn't have it.
    – Tim Schmelter
    Aug 31 at 9:08







  • 4




    Another part that I find important is "Use of the @ prefix for identifiers that are not keywords is permitted, but strongly discouraged as a matter of style." So @newline is tolerated but misleading/confusing.
    – Jeppe Stig Nielsen
    Aug 31 at 9:40










  • I note that your example does not match the text you've quoted from the specification, and that this is a very poor use case. The purpose of this feature is not to allow you to make a formal parameter called @string because that would be a bizarre thing to do. The purpose of the feature is to allow you to, say, extend a third-party class written in a non-C# language that has a virtual member called string. You need to be able to say class D : ThirdParty public override void @string() ... . That would be a by-design use case.
    – Eric Lippert
    Aug 31 at 21:13















up vote
13
down vote













It's a redundant verbatim prefix. From the C# specification:




The prefix "@" enables the use of keywords as identifiers, which is useful when interfacing with other programming languages. The character @ is not actually part of the identifier, so the identifier might be seen in other languages as a normal identifier, without the prefix. An identifier with an @ prefix is called a verbatim identifier. Use of the @ prefix for identifiers that are not keywords is permitted, but strongly discouraged as a matter of style.




A use case would be if you would want to write a function like this:



private void print(string @string) => Console.WriteLine(@string);


Normally you would not be able to name an identifier string because it is a reserved keyword. The @ prefix enables you to do so.






share|improve this answer


















  • 4




    Important part is "The character @ is not actually part of the identifier" because that explains why it compiles even if the variable doesn't have it.
    – Tim Schmelter
    Aug 31 at 9:08







  • 4




    Another part that I find important is "Use of the @ prefix for identifiers that are not keywords is permitted, but strongly discouraged as a matter of style." So @newline is tolerated but misleading/confusing.
    – Jeppe Stig Nielsen
    Aug 31 at 9:40










  • I note that your example does not match the text you've quoted from the specification, and that this is a very poor use case. The purpose of this feature is not to allow you to make a formal parameter called @string because that would be a bizarre thing to do. The purpose of the feature is to allow you to, say, extend a third-party class written in a non-C# language that has a virtual member called string. You need to be able to say class D : ThirdParty public override void @string() ... . That would be a by-design use case.
    – Eric Lippert
    Aug 31 at 21:13













up vote
13
down vote










up vote
13
down vote









It's a redundant verbatim prefix. From the C# specification:




The prefix "@" enables the use of keywords as identifiers, which is useful when interfacing with other programming languages. The character @ is not actually part of the identifier, so the identifier might be seen in other languages as a normal identifier, without the prefix. An identifier with an @ prefix is called a verbatim identifier. Use of the @ prefix for identifiers that are not keywords is permitted, but strongly discouraged as a matter of style.




A use case would be if you would want to write a function like this:



private void print(string @string) => Console.WriteLine(@string);


Normally you would not be able to name an identifier string because it is a reserved keyword. The @ prefix enables you to do so.






share|improve this answer














It's a redundant verbatim prefix. From the C# specification:




The prefix "@" enables the use of keywords as identifiers, which is useful when interfacing with other programming languages. The character @ is not actually part of the identifier, so the identifier might be seen in other languages as a normal identifier, without the prefix. An identifier with an @ prefix is called a verbatim identifier. Use of the @ prefix for identifiers that are not keywords is permitted, but strongly discouraged as a matter of style.




A use case would be if you would want to write a function like this:



private void print(string @string) => Console.WriteLine(@string);


Normally you would not be able to name an identifier string because it is a reserved keyword. The @ prefix enables you to do so.







share|improve this answer














share|improve this answer



share|improve this answer








edited Aug 31 at 13:54









Peter Mortensen

12.9k1983111




12.9k1983111










answered Aug 31 at 9:01









ChristianMurschall

907315




907315







  • 4




    Important part is "The character @ is not actually part of the identifier" because that explains why it compiles even if the variable doesn't have it.
    – Tim Schmelter
    Aug 31 at 9:08







  • 4




    Another part that I find important is "Use of the @ prefix for identifiers that are not keywords is permitted, but strongly discouraged as a matter of style." So @newline is tolerated but misleading/confusing.
    – Jeppe Stig Nielsen
    Aug 31 at 9:40










  • I note that your example does not match the text you've quoted from the specification, and that this is a very poor use case. The purpose of this feature is not to allow you to make a formal parameter called @string because that would be a bizarre thing to do. The purpose of the feature is to allow you to, say, extend a third-party class written in a non-C# language that has a virtual member called string. You need to be able to say class D : ThirdParty public override void @string() ... . That would be a by-design use case.
    – Eric Lippert
    Aug 31 at 21:13













  • 4




    Important part is "The character @ is not actually part of the identifier" because that explains why it compiles even if the variable doesn't have it.
    – Tim Schmelter
    Aug 31 at 9:08







  • 4




    Another part that I find important is "Use of the @ prefix for identifiers that are not keywords is permitted, but strongly discouraged as a matter of style." So @newline is tolerated but misleading/confusing.
    – Jeppe Stig Nielsen
    Aug 31 at 9:40










  • I note that your example does not match the text you've quoted from the specification, and that this is a very poor use case. The purpose of this feature is not to allow you to make a formal parameter called @string because that would be a bizarre thing to do. The purpose of the feature is to allow you to, say, extend a third-party class written in a non-C# language that has a virtual member called string. You need to be able to say class D : ThirdParty public override void @string() ... . That would be a by-design use case.
    – Eric Lippert
    Aug 31 at 21:13








4




4




Important part is "The character @ is not actually part of the identifier" because that explains why it compiles even if the variable doesn't have it.
– Tim Schmelter
Aug 31 at 9:08





Important part is "The character @ is not actually part of the identifier" because that explains why it compiles even if the variable doesn't have it.
– Tim Schmelter
Aug 31 at 9:08





4




4




Another part that I find important is "Use of the @ prefix for identifiers that are not keywords is permitted, but strongly discouraged as a matter of style." So @newline is tolerated but misleading/confusing.
– Jeppe Stig Nielsen
Aug 31 at 9:40




Another part that I find important is "Use of the @ prefix for identifiers that are not keywords is permitted, but strongly discouraged as a matter of style." So @newline is tolerated but misleading/confusing.
– Jeppe Stig Nielsen
Aug 31 at 9:40












I note that your example does not match the text you've quoted from the specification, and that this is a very poor use case. The purpose of this feature is not to allow you to make a formal parameter called @string because that would be a bizarre thing to do. The purpose of the feature is to allow you to, say, extend a third-party class written in a non-C# language that has a virtual member called string. You need to be able to say class D : ThirdParty public override void @string() ... . That would be a by-design use case.
– Eric Lippert
Aug 31 at 21:13





I note that your example does not match the text you've quoted from the specification, and that this is a very poor use case. The purpose of this feature is not to allow you to make a formal parameter called @string because that would be a bizarre thing to do. The purpose of the feature is to allow you to, say, extend a third-party class written in a non-C# language that has a virtual member called string. You need to be able to say class D : ThirdParty public override void @string() ... . That would be a by-design use case.
– Eric Lippert
Aug 31 at 21:13


















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52111891%2fstring-interpolation-what-does-the-sign-inside-the-curly-braces-do%23new-answer', 'question_page');

);

Post as a guest













































































Comments

Popular posts from this blog

What does second last employer means? [closed]

List of Gilmore Girls characters

One-line joke