¿Cómo se usan cadenas textuales con interpolación?
En C#6 hay una nueva característica: cadenas interpoladas.
Estos le permiten poner expresiones directamente en el código, en lugar de depender de índices:
string s = string.Format("Adding \"{0}\" and {1} to foobar.", x, this.Y());
Se convierte en:
string s = $"Adding \"{x}\" and {this.Y()} to foobar.";
Sin embargo, tenemos muchas cadenas a través de múltiples líneas usando cadenas literales (principalmente sentencias SQL) como esta:
string s = string.Format(@"Result...
Adding ""{0}"" and {1} to foobar:
{2}", x, this.Y(), x.GetLog());
Revertir estos a cadenas regulares parece desordenado:
string s = "Result...\r\n" +
$"Adding \"{x}\" and {this.Y()} to foobar:\r\n" +
x.GetLog().ToString();
¿Cómo uso las cadenas textuales e interpoladas juntas?
88
1 answers
Puedes aplicar ambos prefijos $
y @
a la misma cadena:
string s = $@"Result...
Adding ""{x}"" and {this.Y()} to foobar:
{x.GetLog()}";
118
Author: Keith,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-07-26 15:12:37
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-07-26 15:12:37