Код: Выделить всё
var person = new { Name = "Bob" };
string s = $"Hello, {person.Name}.";
С другими типами строк вы можете:
Код: Выделить всё
var multi1 = string.Format(@"Height: {0}
Width: {1}
Background: {2}",
height,
width,
background);
Код: Выделить всё
var multi2 = string.Format(
"Height: {1}{0}" +
"Width: {2}{0}" +
"Background: {3}",
Environment.NewLine,
height,
width,
background);
Код: Выделить всё
var multi3 = $"Height: {height}{Environment.NewLine}Width: {width}{Environment.NewLine}Background: {background}";
Это просто тот случай, когда интерполяция строк не должна использоваться для длинных строк?
Следует ли мы просто используем StringBuilder для более длинных строк?
Код: Выделить всё
var multi4 = new StringBuilder()
.AppendFormat("Width: {0}", width).AppendLine()
.AppendFormat("Height: {0}", height).AppendLine()
.AppendFormat("Background: {0}", background).AppendLine()
.ToString();
Подробнее здесь: https://stackoverflow.com/questions/332 ... ng-literal