c# - What does $ mean before a string? -
i going use verbatim string mistakenly typed $ instead of @.
but compiler didn't give me error , compiled successfully.
i want know , does. searched couldn't find anything.
however not verbatim string because can't write:
string str = $"text\"; does know $ before string stand in c#.
string str = $"text"; i'm using visual studio 2015 ctp.
$ short-hand string.format , used string interpolations, new feature of c# 6. used in case, nothing, string.format() nothing.
it comes own when used build strings reference other values. had written as:
var anint = 1; var abool = true; var astring = "3"; var formated = string.format("{0},{1},{2}", anint, abool, astring); now becomes:
var anint = 1; var abool = true; var astring = "3"; var formated = $"{anint},{abool},{astring}"; there's alternative - less known - form of string interpolation using $@ (the order of 2 symbols important). allows features of @"" string mixed $"" support string interpolations without need \\ throughout string. following 2 lines:
var somedir = "a"; console.writeline($@"c:\{somedir}\b\c"); will output:
c:\a\b\c
Comments
Post a Comment