You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/csharp/language-reference/tokens/interpolated.md
+8-8Lines changed: 8 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,7 +16,7 @@ ms.author: ronpet
16
16
---
17
17
# $ - string interpolation (C# Reference)
18
18
19
-
The `$` special character identifies a string literal as an *interpolated string*. An interpolated string is a string literal that might contain *interpolated expressions*. When an interpolated string is resolved to a result string, items with interpolated expressions are replaced by the string representations of the expression results. This feature is available in C# 6 and later versions of the language.
19
+
The `$` special character identifies a string literal as an *interpolated string*. An interpolated string is a string literal that might contain *interpolation expressions*. When an interpolated string is resolved to a result string, items with interpolation expressions are replaced by the string representations of the expression results. This feature is available in C# 6 and later versions of the language.
20
20
21
21
String interpolation provides a more readable and convenient syntax to create formatted strings than a [string composite formatting](../../../standard/base-types/composite-formatting.md) feature. The following example uses both features to produce the same output:
22
22
@@ -26,18 +26,18 @@ String interpolation provides a more readable and convenient syntax to create fo
26
26
27
27
To identify a string literal as an interpolated string, prepend it with the `$` symbol. You cannot have any white space between the `$` and the `"` that starts a string literal. Doing so causes a compile-time error.
28
28
29
-
The structure of an item with an interpolated expression is as follows:
29
+
The structure of an item with an interpolation expression is as follows:
Elements in square brackets are optional. The following table describes each element:
36
36
37
37
|Element|Description|
38
38
|-------------|-----------------|
39
-
|`interpolatedExpression`|The expression that produces a result to be formatted. String representation of the `null` result is <xref:System.String.Empty?displayProperty=nameWithType>.|
40
-
|`alignment`|The constant expression whose value defines the minimum number of characters in the string representation of the result of the interpolated expression. If positive, the string representation is right-aligned; if negative, it's left-aligned. For more information, see [Alignment Component](../../../standard/base-types/composite-formatting.md#alignment-component).|
39
+
|`interpolationExpression`|The expression that produces a result to be formatted. String representation of the `null` result is <xref:System.String.Empty?displayProperty=nameWithType>.|
40
+
|`alignment`|The constant expression whose value defines the minimum number of characters in the string representation of the result of the interpolation expression. If positive, the string representation is right-aligned; if negative, it's left-aligned. For more information, see [Alignment Component](../../../standard/base-types/composite-formatting.md#alignment-component).|
41
41
|`formatString`|A format string that is supported by the type of the expression result. For more information, see [Format String Component](../../../standard/base-types/composite-formatting.md#format-string-component).|
42
42
43
43
The following example uses optional formatting components described above:
@@ -48,9 +48,9 @@ The following example uses optional formatting components described above:
48
48
49
49
To include a brace, "{" or "}", in the text produced by an interpolated string, use two braces, "{{" or "}}". For more information, see [Escaping Braces](../../../standard/base-types/composite-formatting.md#escaping-braces).
50
50
51
-
As the colon (":") has special meaning in an interpolated expression item, in order to use a [conditional operator](../operators/conditional-operator.md) in an interpolated expression, enclose that expression in parentheses.
51
+
As the colon (":") has special meaning in an interpolation expression item, in order to use a [conditional operator](../operators/conditional-operator.md) in an interpolation expression, enclose that expression in parentheses.
52
52
53
-
The following example shows how to include a brace in a result string and how to use a conditional operator in an interpolated expression:
53
+
The following example shows how to include a brace in a result string and how to use a conditional operator in an interpolation expression:
54
54
55
55
[!code-csharp-interactive[example with ternary conditional operator](~/samples/snippets/csharp/language-reference/tokens/string-interpolation.cs#3)]
56
56
@@ -63,7 +63,7 @@ A verbatim interpolated string starts with the `$` character followed by the `@`
63
63
64
64
There are three implicit conversions from an interpolated string:
65
65
66
-
1. Conversion of an interpolated string to a <xref:System.String> instance that is the result of interpolated string resolution with interpolated expression items being replaced with the properly formatted string representations of their results. This conversion uses the current culture.
66
+
1. Conversion of an interpolated string to a <xref:System.String> instance that is the result of interpolated string resolution with interpolation expression items being replaced with the properly formatted string representations of their results. This conversion uses the current culture.
67
67
68
68
1. Conversion of an interpolated string to a <xref:System.FormattableString> instance that represents a composite format string along with the expression results to be formatted. That allows you to create multiple result strings with culture-specific content from a single <xref:System.FormattableString> instance. To do that call one of the following methods:
Copy file name to clipboardExpand all lines: docs/csharp/tutorials/string-interpolation.md
+10-10Lines changed: 10 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,17 +21,17 @@ To identify a string literal as an interpolated string, prepend it with the `$`
21
21
As the example shows, you include an expression in an interpolated string by enclosing it with braces:
22
22
23
23
```
24
-
{<interpolatedExpression>}
24
+
{<interpolationExpression>}
25
25
```
26
26
27
27
Interpolated strings support all the capabilities of the [string composite formatting](../../standard/base-types/composite-formatting.md) feature. That makes them a more readable alternative to the use of the <xref:System.String.Format%2A?displayProperty=nameWithType> method.
28
28
29
-
## How to specify a format string for an interpolated expression
29
+
## How to specify a format string for an interpolation expression
30
30
31
-
You specify a format string that is supported by the type of the expression result by following the interpolated expression with a colon (":") and the format string:
31
+
You specify a format string that is supported by the type of the expression result by following the interpolation expression with a colon (":") and the format string:
32
32
33
33
```
34
-
{<interpolatedExpression>:<formatString>}
34
+
{<interpolationExpression>:<formatString>}
35
35
```
36
36
37
37
The following example shows how to specify standard and custom format strings for expressions that produce date and time or numeric results:
@@ -40,20 +40,20 @@ The following example shows how to specify standard and custom format strings fo
40
40
41
41
For more information, see the [Format String Component](../../standard/base-types/composite-formatting.md#format-string-component) section of the [Composite Formatting](../../standard/base-types/composite-formatting.md) topic. That section provides links to the topics that describe standard and custom format strings supported by .NET base types.
42
42
43
-
## How to control the field width and alignment of the formatted interpolated expression
43
+
## How to control the field width and alignment of the formatted interpolation expression
44
44
45
-
You specify the minimum field width and the alignment of the formatted expression result by following the interpolated expression with a comma (",") and the constant expression:
45
+
You specify the minimum field width and the alignment of the formatted expression result by following the interpolation expression with a comma (",") and the constant expression:
46
46
47
47
```
48
-
{<interpolatedExpression>,<alignment>}
48
+
{<interpolationExpression>,<alignment>}
49
49
```
50
50
51
51
If the *alignment* value is positive, the formatted expression result is right-aligned; if negative, it's left-aligned.
52
52
53
53
If you need to specify both alignment and a format string, start with the alignment component:
## How to use a ternary conditional operator `?:` in an interpolated expression
79
+
## How to use a ternary conditional operator `?:` in an interpolation expression
80
80
81
-
As the colon (":") has special meaning in an item with an interpolated expression, in order to use a [conditional operator](../language-reference/operators/conditional-operator.md) in an expression, enclose it in parentheses, as the following example shows:
81
+
As the colon (":") has special meaning in an item with an interpolation expression, in order to use a [conditional operator](../language-reference/operators/conditional-operator.md) in an expression, enclose it in parentheses, as the following example shows:
0 commit comments