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/core/extensions/globalization.md
+5-9Lines changed: 5 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -128,15 +128,11 @@ How you handle date and time values depends on whether they are displayed in the
128
128
129
129
Typically, when dates and times are displayed in the user interface, you should use the formatting conventions of the user's culture, which is defined by the <xref:System.Globalization.CultureInfo.CurrentCulture%2A?displayProperty=nameWithType> property and by the <xref:System.Globalization.DateTimeFormatInfo> object returned by the `CultureInfo.CurrentCulture.DateTimeFormat` property. The formatting conventions of the current culture are automatically used when you format a date by using any of these methods:
130
130
131
-
- The parameterless <xref:System.DateTime.ToString?displayProperty=nameWithType> method
132
-
133
-
- The <xref:System.DateTime.ToString%28System.String%29?displayProperty=nameWithType> method, which includes a format string
134
-
135
-
- The parameterless <xref:System.DateTimeOffset.ToString?displayProperty=nameWithType> method
136
-
137
-
- The <xref:System.DateTimeOffset.ToString%28System.String%29?displayProperty=nameWithType>, which includes a format string
138
-
139
-
- The [composite formatting](../../standard/base-types/composite-formatting.md) feature, when it is used with dates
131
+
- The parameterless <xref:System.DateTime.ToString?displayProperty=nameWithType> method.
132
+
- The <xref:System.DateTime.ToString%28System.String%29?displayProperty=nameWithType> method, which includes a format string.
133
+
- The parameterless <xref:System.DateTimeOffset.ToString?displayProperty=nameWithType> method.
134
+
- The <xref:System.DateTimeOffset.ToString%28System.String%29?displayProperty=nameWithType>, which includes a format string.
135
+
- The [composite formatting](../../standard/base-types/composite-formatting.md) feature, when it is used with dates.
140
136
141
137
The following example displays sunrise and sunset data twice for October 11, 2012. It first sets the current culture to Croatian (Croatia), and then to English (United Kingdom). In each case, the dates and times are displayed in the format that is appropriate for that culture.
Elements in square brackets are optional. The following table describes each element:
36
36
37
-
| Element | Description |
38
-
|--|--|
37
+
| Element | Description |
38
+
|---------------------------|-------------|
39
39
|`interpolationExpression`| The expression that produces a result to be formatted. When the expression is `null`, the output is the empty string (<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 expression result. If positive, the string representation is right-aligned; if negative, left-aligned. For more information, see the [Alignment component](../../../standard/base-types/composite-formatting.md#alignment-component) section of the [Composite formatting](../../../standard/base-types/composite-formatting.md) article. |
41
-
|`formatString`| A format string supported by the type of the expression result. 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) article. |
40
+
|`width`| The constant expression whose value defines the minimum number of characters in the string representation of the expression result. If positive, the string representation is right-aligned; if negative, left-aligned. For more information, see the [Width component](../../../standard/base-types/composite-formatting.md#width-component) section of the [Composite formatting](../../../standard/base-types/composite-formatting.md) article. |
41
+
|`formatString`| A format string supported by the type of the expression result. 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) article. |
42
42
43
43
The following example uses optional formatting components described in the preceding table:
44
44
@@ -95,7 +95,7 @@ If you're new to string interpolation, see the [String interpolation in C#](../.
95
95
The compiler checks if an interpolated string is assigned to a type that satisfies the [_interpolated string handler pattern_](~/_csharplang/proposals/csharp-10.0/improved-interpolated-strings.md#the-handler-pattern). An _interpolated string handler_ is a type that converts the interpolated string into a result string. When an interpolated string has the type `string`, it's processed by the <xref:System.Runtime.CompilerServices.DefaultInterpolatedStringHandler?displayProperty=fullName>. For the example of a custom interpolated string handler, see the [Write a custom string interpolation handler](../../advanced-topics/performance/interpolated-string-handler.md) tutorial. Use of an interpolated string handler is an advanced scenario, typically required for performance reasons.
96
96
97
97
> [!NOTE]
98
-
> One side effect of interpolated string handlers is that a custom handler, including <xref:System.Runtime.CompilerServices.DefaultInterpolatedStringHandler?displayProperty=nameWithType>, may not evaluate all the interpolation expressions within the interpolated string under all conditions. That means side effects of those expressions may not occur.
98
+
> One side effect of interpolated string handlers is that a custom handler, including <xref:System.Runtime.CompilerServices.DefaultInterpolatedStringHandler?displayProperty=nameWithType>, might not evaluate all the interpolation expressions within the interpolated string under all conditions. That means side effects of those expressions might not occur.
99
99
100
100
If an interpolated string has the type `string`, it's typically transformed into a <xref:System.String.Format%2A?displayProperty=nameWithType> method call. The compiler can replace <xref:System.String.Format%2A?displayProperty=nameWithType> with <xref:System.String.Concat%2A?displayProperty=nameWithType> if the analyzed behavior would be equivalent to concatenation.
Copy file name to clipboardExpand all lines: docs/csharp/programming-guide/strings/index.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -108,7 +108,7 @@ A format string is a string whose contents are determined dynamically at run tim
108
108
109
109
You declare [*Interpolated strings*](../../language-reference/tokens/interpolated.md) with the `$` special character. An interpolated string includes interpolated expressions in braces. If you're new to string interpolation, see the [String interpolation - C# interactive tutorial](../../tutorials/exploration/interpolated-strings.yml) for a quick overview.
110
110
111
-
Use string interpolation to improve the readability and maintainability of your code. String interpolation achieves the same results as the `String.Format` method, but improves ease of use and inline clarity.
111
+
Use string interpolation to improve the readability and maintainability of your code. String interpolation achieves the same results as the `String.Format` method, but is easier to use and improves inline clarity.
Copy file name to clipboardExpand all lines: docs/csharp/tutorials/string-interpolation.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
@@ -25,7 +25,7 @@ Interpolated strings support all the capabilities of the [string composite forma
25
25
26
26
## How to specify a format string for an interpolation expression
27
27
28
-
To specify a format string that is supported by the type of the expression result, follow the interpolation expression with a colon (":") and the format string:
28
+
To specify a format string that's supported by the type of the expression result, follow the interpolation expression with a colon (":") and the format string:
29
29
30
30
```csharp
31
31
{<interpolationExpression>:<formatString>}
@@ -42,24 +42,24 @@ For more information, see the [Format string component](../../standard/base-type
42
42
To specify the minimum field width and the alignment of the formatted expression result, follow the interpolation expression with a comma (",") and the constant expression:
43
43
44
44
```csharp
45
-
{<interpolationExpression>,<alignment>}
45
+
{<interpolationExpression>,<width>}
46
46
```
47
47
48
-
If the *alignment* value is positive, the formatted expression result is right-aligned; if negative, it's left-aligned.
48
+
If the *width* value is positive, the formatted expression result is right-aligned; if negative, it's left-aligned.
49
49
50
-
If you need to specify both alignment and a format string, start with the alignment component:
50
+
If you need to specify both width and a format string, start with the width component:
As the example output shows, if the length of the formatted expression result exceeds specified field width, the *alignment* value is ignored.
60
+
As the example output shows, if the length of the formatted expression result exceeds specified field width, the *width* value is ignored.
61
61
62
-
For more information, see the [Alignment component](../../standard/base-types/composite-formatting.md#alignment-component) section of the [Composite formatting](../../standard/base-types/composite-formatting.md) article.
62
+
For more information, see the [Width component](../../standard/base-types/composite-formatting.md#width-component) section of the [Composite formatting](../../standard/base-types/composite-formatting.md) article.
63
63
64
64
## How to use escape sequences in an interpolated string
|`configuration`|The root element in every configuration file used by the common language runtime and .NET Framework applications.|
54
+
|`runtime`|Contains information about runtime initialization options.|
55
55
56
56
## Remarks
57
57
58
-
Starting with the .NET Framework 4, the <xref:System.TimeSpan?displayProperty=nameWithType> structure implements the <xref:System.IFormattable> interface and supports formatting operations with standard and custom format strings. If a parsing method encounters an unsupported format specifier or format string, it throws a <xref:System.FormatException>.
58
+
Starting with .NET Framework 4, the <xref:System.TimeSpan?displayProperty=nameWithType> structure implements the <xref:System.IFormattable> interface and supports formatting operations with standard and custom format strings. If a parsing method encounters an unsupported format specifier or format string, it throws a <xref:System.FormatException>.
59
59
60
-
In previous versions of the .NET Framework, the <xref:System.TimeSpan> structure did not implement <xref:System.IFormattable> and did not support format strings. However, many developers mistakenly assumed that <xref:System.TimeSpan> did support a set of format strings and used them in [composite formatting operations](../../../../standard/base-types/composite-formatting.md) with methods such as <xref:System.String.Format%2A?displayProperty=nameWithType>. Ordinarily, if a type implements <xref:System.IFormattable> and supports format strings, calls to formatting methods with unsupported format strings usually throw a <xref:System.FormatException>. However, because <xref:System.TimeSpan> did not implement <xref:System.IFormattable>, the runtime ignored the format string and instead called the <xref:System.TimeSpan.ToString?displayProperty=nameWithType> method. This means that, although the format strings had no effect on the formatting operation, their presence did not result in a <xref:System.FormatException>.
60
+
In previous versions of .NET Framework, the <xref:System.TimeSpan> structure did not implement <xref:System.IFormattable> and did not support format strings. However, many developers mistakenly assumed that <xref:System.TimeSpan> did support a set of format strings and used them in [composite formatting operations](../../../../standard/base-types/composite-formatting.md) with methods such as <xref:System.String.Format%2A?displayProperty=nameWithType>. Ordinarily, if a type implements <xref:System.IFormattable> and supports format strings, calls to formatting methods with unsupported format strings usually throw a <xref:System.FormatException>. However, because <xref:System.TimeSpan> did not implement <xref:System.IFormattable>, the runtime ignored the format string and instead called the <xref:System.TimeSpan.ToString?displayProperty=nameWithType> method. This means that, although the format strings had no effect on the formatting operation, their presence did not result in a <xref:System.FormatException>.
61
61
62
62
For cases in which legacy code passes a composite formatting method and an invalid format string, and that code cannot be recompiled, you can use the `<TimeSpan_LegacyFormatMode>` element to restore the legacy <xref:System.TimeSpan> behavior. When you set the `enabled` attribute of this element to `true`, the composite formatting method results in a call to <xref:System.TimeSpan.ToString?displayProperty=nameWithType> rather than <xref:System.TimeSpan.ToString%28System.String%2CSystem.IFormatProvider%29?displayProperty=nameWithType>, and a <xref:System.FormatException> is not thrown.
63
63
@@ -68,7 +68,7 @@ The following example instantiates a <xref:System.TimeSpan> object and attempts
When you run the example on the .NET Framework 3.5 or on an earlier version, it displays the following output:
71
+
When you run the example on .NET Framework 3.5 or on an earlier version, it displays the following output:
72
72
73
73
```console
74
74
12:30:45
@@ -80,7 +80,7 @@ This differs markedly from the output if you run the example on the .NET Framewo
80
80
Invalid Format
81
81
```
82
82
83
-
However, if you add the following configuration file to the example's directory and then run the example on the .NET Framework 4 or later version, the output is identical to that produced by the example when it is run on .NET Framework 3.5.
83
+
However, if you add the following configuration file to the example's directory and then run the example on .NET Framework 4 or a later version, the output is identical to that produced by the example when it is run on .NET Framework 3.5.
> Instead of calling the **String.Format** method or using [composite format strings](../../../standard/base-types/composite-formatting.md), you can use *interpolated strings* if your language supports them. An interpolated string is a string that contains *interpolated expressions*. Each interpolated expression is resolved with the expression's value and included in the result string when the string is assigned. For more information, see [String interpolation (C# Reference)](../../../csharp/language-reference/tokens/interpolated.md) and [Interpolated Strings (Visual Basic Reference)](../../../visual-basic/programming-guide/language-features/strings/interpolated-strings.md).
2
+
> Instead of calling the **String.Format** method or using [composite format strings](../../../standard/base-types/composite-formatting.md), you can use *interpolated strings* if your language supports them. An interpolated string is a string that contains *interpolated expressions*. Each interpolated expression is resolved with the expression's value and included in the result string when the string is assigned. For more information, see [String interpolation (C# Reference)](../../../csharp/language-reference/tokens/interpolated.md) and [Interpolated strings (Visual Basic Reference)](../../../visual-basic/programming-guide/language-features/strings/interpolated-strings.md).
Copy file name to clipboardExpand all lines: docs/fundamentals/runtime-libraries/system-double.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -191,7 +191,7 @@ The <xref:System.Double> structure and related types provide methods to perform
191
191
192
192
-**Rounding**. Rounding is often used as a technique for reducing the impact of differences between values caused by problems of floating-point representation and precision. You can round a <xref:System.Double> value by calling the <xref:System.Math.Round%2A?displayProperty=nameWithType> method.
193
193
194
-
-**Formatting**. You can convert a <xref:System.Double> value to its string representation by calling the <xref:System.Double.ToString%2A> method or by using the composite formatting feature. For information about how format strings control the string representation of floating-point values, see the [Standard Numeric Format Strings](../../standard/base-types/standard-numeric-format-strings.md) and [Custom Numeric Format Strings](../../standard/base-types/custom-numeric-format-strings.md) topics.
194
+
-**Formatting**. You can convert a <xref:System.Double> value to its string representation by calling the <xref:System.Double.ToString%2A> method or by using the composite formatting feature. For information about how format strings control the string representation of floating-point values, see [Standard Numeric Format Strings](../../standard/base-types/standard-numeric-format-strings.md) and [Custom Numeric Format Strings](../../standard/base-types/custom-numeric-format-strings.md).
195
195
196
196
-**Parsing strings**. You can convert the string representation of a floating-point value to a <xref:System.Double> value by calling either the <xref:System.Double.Parse%2A> or <xref:System.Double.TryParse%2A> method. If the parse operation fails, the <xref:System.Double.Parse%2A> method throws an exception, whereas the <xref:System.Double.TryParse%2A> method returns `false`.
0 commit comments