Skip to content

Commit 2e63966

Browse files
v-mepamairaw
andauthored
.NET Interactive: Enable_try_dotnet_to_batch_11b (#4369)
* enable_try_dotnet_to_batch_11b * Update xml/System/Boolean.xml Co-authored-by: Maira Wenzel <[email protected]> * add_interactive_to_previous_example Co-authored-by: Maira Wenzel <[email protected]>
1 parent 5a7858a commit 2e63966

File tree

5 files changed

+48
-47
lines changed

5 files changed

+48
-47
lines changed

xml/System/Boolean.xml

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -104,18 +104,18 @@
104104
105105
The following example illustrates formatting with the <xref:System.Boolean.ToString%2A> method. Note that the example uses the [composite formatting](/dotnet/standard/base-types/composite-formatting) feature, so the <xref:System.Boolean.ToString%2A> method is called implicitly.
106106
107-
[!code-csharp[System.Boolean.Structure#3](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.boolean.structure/cs/tostring1.cs#3)]
108-
[!code-vb[System.Boolean.Structure#3](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.boolean.structure/vb/tostring1.vb#3)]
107+
:::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.boolean.structure/cs/tostring1.cs" interactive="try-dotnet" id="Snippet3":::
108+
:::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.boolean.structure/vb/tostring1.vb" id="Snippet3":::
109109
110110
Because the <xref:System.Boolean> structure can have only two values, it is easy to add custom formatting. For simple custom formatting in which other string literals are substituted for "True" and "False", you can use any conditional evaluation feature supported by your language, such as the [conditional operator](/dotnet/csharp/language-reference/operators/conditional-operator) in C# or the [If operator](/dotnet/visual-basic/language-reference/operators/if-operator) in Visual Basic. The following example uses this technique to format <xref:System.Boolean> values as "Yes" and "No" rather than "True" and "False".
111111
112-
[!code-csharp[System.Boolean.Structure#4](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.boolean.structure/cs/tostring2.cs#4)]
113-
[!code-vb[System.Boolean.Structure#4](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.boolean.structure/vb/tostring2.vb#4)]
112+
:::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.boolean.structure/cs/tostring2.cs" interactive="try-dotnet" id="Snippet4":::
113+
:::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.boolean.structure/vb/tostring2.vb" id="Snippet4":::
114114
115115
For more complex custom formatting operations, including culture-sensitive formatting, you can call the <xref:System.String.Format%28System.IFormatProvider%2CSystem.String%2CSystem.Object%5B%5D%29?displayProperty=nameWithType> method and provide an <xref:System.ICustomFormatter> implementation. The following example implements the <xref:System.ICustomFormatter> and <xref:System.IFormatProvider> interfaces to provide culture-sensitive Boolean strings for the English (United States), French (France), and Russian (Russia) cultures.
116116
117-
[!code-csharp[System.Boolean.Structure#5](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.boolean.structure/cs/format3.cs#5)]
118-
[!code-vb[System.Boolean.Structure#5](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.boolean.structure/vb/format3.vb#5)]
117+
:::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.boolean.structure/cs/format3.cs" interactive="try-dotnet" id="Snippet5":::
118+
:::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.boolean.structure/vb/format3.vb" id="Snippet5":::
119119
120120
Optionally, you can use [resource files](/dotnet/framework/resources/) to define culture-specific Boolean strings.
121121
@@ -129,15 +129,15 @@
129129
130130
All conversions from integral or floating-point numbers to Boolean values convert non-zero values to `true` and zero values to `false`. The following example illustrates this by calling selected overloads of the <xref:System.Convert.ToBoolean%2A?displayProperty=nameWithType> class.
131131
132-
[!code-csharp[System.Boolean.Structure#6](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.boolean.structure/cs/conversion1.cs#6)]
133-
[!code-vb[System.Boolean.Structure#6](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.boolean.structure/vb/conversion1.vb#6)]
132+
:::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.boolean.structure/cs/conversion1.cs" interactive="try-dotnet" id="Snippet6":::
133+
:::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.boolean.structure/vb/conversion1.vb" id="Snippet6":::
134134
135135
When converting from floating-point values to Boolean values, the conversion methods perform an exact comparison with zero. If the floating-point value has lost precision, the result can be unexpected. This is illustrated in the following example, in which a <xref:System.Double> variable whose value should be zero is converted to a Boolean value. As the example shows, the result is `true` because repeated additions of 0.2 have resulted in a loss of precision.
136136
137137
When converting from Boolean to numeric values, the conversion methods of the <xref:System.Convert> class convert `true` to 1 and `false` to 0. However, Visual Basic conversion functions convert `true` to either 255 (for conversions to <xref:System.Byte> values) or -1 (for all other numeric conversions). The following example converts `true` to numeric values by using a <xref:System.Convert> method, and, in the case of the Visual Basic example, by using the Visual Basic language's own conversion operator.
138138
139-
[!code-csharp[System.Boolean.Structure#8](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.boolean.structure/cs/conversion3.cs#8)]
140-
[!code-vb[System.Boolean.Structure#8](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.boolean.structure/vb/conversion3.vb#8)]
139+
:::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.boolean.structure/cs/conversion3.cs" interactive="try-dotnet" id="Snippet8":::
140+
:::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.boolean.structure/vb/conversion3.vb" id="Snippet8":::
141141
142142
For conversions from <xref:System.Boolean> to string values, see the [Formatting Boolean Values](#Formatting) section. For conversions from strings to <xref:System.Boolean> values, see the [Parsing Boolean Values](#Parsing) section.
143143
@@ -147,13 +147,13 @@
147147
148148
The following example uses the <xref:System.Boolean.Parse%2A> and <xref:System.Boolean.TryParse%2A> methods to parse a number of strings. Note that only the case-insensitive equivalents of "True" and "False" can be successfully parsed.
149149
150-
[!code-csharp[System.Boolean.Structure#2](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.boolean.structure/cs/parse2.cs#2)]
151-
[!code-vb[System.Boolean.Structure#2](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.boolean.structure/vb/parse2.vb#2)]
150+
:::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.boolean.structure/cs/parse2.cs" interactive="try-dotnet" id="Snippet2":::
151+
:::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.boolean.structure/vb/parse2.vb" id="Snippet2":::
152152
153153
If you are programming in Visual Basic, you can use the `CBool` function to convert the string representation of a number to a Boolean value. "0" is converted to `false`, and the string representation of any non-zero value is converted to `true`. If you are not programming in Visual Basic, you must convert your numeric string to a number before converting it to a Boolean. The following example illustrates this by converting an array of integers to Boolean values.
154154
155-
[!code-csharp[System.Boolean.Structure#9](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.boolean.structure/cs/parse3.cs#9)]
156-
[!code-vb[System.Boolean.Structure#9](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.boolean.structure/vb/parse3.vb#9)]
155+
:::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.boolean.structure/cs/parse3.cs" interactive="try-dotnet" id="Snippet9":::
156+
:::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.boolean.structure/vb/parse3.vb" id="Snippet9":::
157157
158158
<a name="Comparing"></a>
159159
## Comparing Boolean values
@@ -186,8 +186,8 @@
186186
187187
The following example calls the <xref:System.BitConverter.GetBytes%2A?displayProperty=nameWithType> method to convert a Boolean value to its binary representation and displays the individual bits of the value, and then calls the <xref:System.BitConverter.ToBoolean%2A?displayProperty=nameWithType> method to restore the value from its binary representation.
188188
189-
[!code-csharp[System.Boolean.Structure#1](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.boolean.structure/cs/binary1.cs#1)]
190-
[!code-vb[System.Boolean.Structure#1](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.boolean.structure/vb/binary1.vb#1)]
189+
:::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.boolean.structure/cs/binary1.cs" interactive="try-dotnet" id="Snippet1":::
190+
:::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.boolean.structure/vb/binary1.vb" id="Snippet1":::
191191
192192
<a name="Operations"></a>
193193
## Performing operations with Boolean values
@@ -198,8 +198,8 @@
198198
199199
The following example uses a simple console app to illustrate the use of Boolean variables as flags. The app accepts command-line parameters that enable output to be redirected to a specified file (the `/f` switch), and that enable output to be sent both to a specified file and to the console (the `/b` switch). The app defines a flag named `isRedirected` to indicate whether output is to be sent to a file, and a flag named `isBoth` to indicate that output should be sent to the console.
200200
201-
[!code-csharp[System.Boolean.Structure#10](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.boolean.structure/cs/operations1.cs#10)]
202-
[!code-vb[System.Boolean.Structure#10](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.boolean.structure/vb/operations1.vb#10)]
201+
:::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.boolean.structure/cs/operations1.cs" id="Snippet10":::
202+
:::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.boolean.structure/vb/operations1.vb" id="Snippet10":::
203203
204204
### Booleans and arithmetic operations
205205
A Boolean value is sometimes used to indicate the presence of a condition that triggers a mathematical calculation. For example, a `hasShippingCharge` variable might serve as a flag to indicate whether to add shipping charges to an invoice amount.

xml/System/DateTime.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7762,8 +7762,8 @@ The value of the current <xref:System.DateTime> object is formatted using the pa
77627762
## Examples
77637763
The following example demonstrates the <xref:System.DateTime.ToShortDateString%2A> method. It also shows that the result of calling the <xref:System.DateTime.ToShortDateString%2A> method is identical to calling the <xref:System.DateTime.ToString%28System.String%29?displayProperty=nameWithType> method with "d" as the format parameter.
77647764

7765-
[!code-csharp[System.DateTime.ToShortDateString#1](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.ToShortDateString/cs/ToShortDateString.cs#1)]
7766-
[!code-vb[System.DateTime.ToShortDateString#1](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.ToShortDateString/vb/ToShortDateString.vb#1)]
7765+
:::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.ToShortDateString/cs/ToShortDateString.cs" interactive="try-dotnet" id="Snippet1":::
7766+
:::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.ToShortDateString/vb/ToShortDateString.vb" id="Snippet1":::
77677767

77687768
]]></format>
77697769
</remarks>

xml/System/Decimal.xml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,15 @@
9292
## Remarks
9393
The <xref:System.Decimal> value type represents decimal numbers ranging from positive 79,228,162,514,264,337,593,543,950,335 to negative 79,228,162,514,264,337,593,543,950,335. The default value of a `Decimal` is 0. The <xref:System.Decimal> value type is appropriate for financial calculations that require large numbers of significant integral and fractional digits and no round-off errors. The <xref:System.Decimal> type does not eliminate the need for rounding. Rather, it minimizes errors due to rounding. For example, the following code produces a result of 0.9999999999999999999999999999 instead of 1.
9494

95-
[!code-cpp[System.Decimal.Class#1](~/samples/snippets/cpp/VS_Snippets_CLR_System/system.Decimal.Class/cpp/decimal1.cpp#1)]
96-
[!code-csharp[System.Decimal.Class#1](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Decimal.Class/cs/DecimalDivision_46630_1.cs#1)]
97-
[!code-vb[System.Decimal.Class#1](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Decimal.Class/vb/DecimalDivision_46630_1.vb#1)]
95+
:::code language="cpp" source="~/samples/snippets/cpp/VS_Snippets_CLR_System/system.Decimal.Class/cpp/decimal1.cpp" id="Snippet1":::
96+
:::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Decimal.Class/cs/DecimalDivision_46630_1.cs" interactive="try-dotnet-method" id="Snippet1":::
97+
:::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Decimal.Class/vb/DecimalDivision_46630_1.vb" id="Snippet1":::
9898

9999
When the result of the division and multiplication is passed to the <xref:System.Math.Round%2A> method, the result suffers no loss of precision, as the following code shows.
100100

101-
[!code-cpp[System.Decimal.Class#2](~/samples/snippets/cpp/VS_Snippets_CLR_System/system.Decimal.Class/cpp/decimal2.cpp#2)]
102-
[!code-csharp[System.Decimal.Class#2](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Decimal.Class/cs/DecimalDivision_46630_1.cs#2)]
103-
[!code-vb[System.Decimal.Class#2](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Decimal.Class/vb/DecimalDivision_46630_1.vb#2)]
101+
:::code language="cpp" source="~/samples/snippets/cpp/VS_Snippets_CLR_System/system.Decimal.Class/cpp/decimal2.cpp" id="Snippet2":::
102+
:::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Decimal.Class/cs/DecimalDivision_46630_1.cs" interactive="try-dotnet-method" id="Snippet2":::
103+
:::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Decimal.Class/vb/DecimalDivision_46630_1.vb" id="Snippet2":::
104104

105105
A decimal number is a floating-point value that consists of a sign, a numeric value where each digit in the value ranges from 0 to 9, and a scaling factor that indicates the position of a floating decimal point that separates the integral and fractional parts of the numeric value.
106106

@@ -7022,8 +7022,8 @@ This member is an explicit interface member implementation. It can be used only
70227022
## Examples
70237023
The following example displays the string representation of a <xref:System.Decimal> value using <xref:System.Globalization.CultureInfo> objects that represent several different cultures.
70247024

7025-
[!code-csharp[System.Decimal.ToString#3](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Decimal.ToString/CS/ToString2.cs#3)]
7026-
[!code-vb[System.Decimal.ToString#3](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Decimal.ToString/VB/ToString2.vb#3)]
7025+
:::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Decimal.ToString/CS/ToString2.cs" interactive="try-dotnet-method" id="Snippet3":::
7026+
:::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Decimal.ToString/VB/ToString2.vb" id="Snippet3":::
70277027

70287028
]]></format>
70297029
</remarks>
@@ -7197,8 +7197,8 @@ This member is an explicit interface member implementation. It can be used only
71977197
## Examples
71987198
The following example displays a <xref:System.Decimal> value using each of the supported standard numeric format specifiers for several different cultures.
71997199

7200-
[!code-csharp[System.Decimal.ToString#5](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Decimal.ToString/CS/ToString2.cs#5)]
7201-
[!code-vb[System.Decimal.ToString#5](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Decimal.ToString/VB/ToString2.vb#5)]
7200+
:::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Decimal.ToString/CS/ToString2.cs" interactive="try-dotnet-method" id="Snippet5":::
7201+
:::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Decimal.ToString/VB/ToString2.vb" id="Snippet5":::
72027202

72037203
]]></format>
72047204
</remarks>

xml/System/Enum.xml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -642,9 +642,9 @@
642642
## Examples
643643
The following example illustrates the use of `GetName`.
644644
645-
[!code-cpp[enumgetname#1](~/samples/snippets/cpp/VS_Snippets_CLR/enumgetname/CPP/EnumGetName.cpp#1)]
646-
[!code-csharp[enumgetname#1](~/samples/snippets/csharp/VS_Snippets_CLR/enumgetname/CS/EnumGetName.cs#1)]
647-
[!code-vb[enumgetname#1](~/samples/snippets/visualbasic/VS_Snippets_CLR/enumgetname/VB/EnumGetName.vb#1)]
645+
:::code language="cpp" source="~/samples/snippets/cpp/VS_Snippets_CLR/enumgetname/CPP/EnumGetName.cpp" id="Snippet1":::
646+
:::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR/enumgetname/CS/EnumGetName.cs" interactive="try-dotnet" id="Snippet1":::
647+
:::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR/enumgetname/VB/EnumGetName.vb" id="Snippet1":::
648648
649649
]]></format>
650650
</remarks>
@@ -901,8 +901,8 @@
901901
## Remarks
902902
The elements of the array are sorted by the binary values of the enumeration constants (that is, by their unsigned magnitude). The following example displays information about the array returned by the <xref:System.Enum.GetValues%2A> method for an enumeration that includes a negative value, zero, and a positive value.
903903
904-
[!code-csharp[System.Enum.GetValues#1](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.enum.getvalues/cs/getvalues1.cs#1)]
905-
[!code-vb[System.Enum.GetValues#1](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.enum.getvalues/vb/getvalues1.vb#1)]
904+
:::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.enum.getvalues/cs/getvalues1.cs" interactive="try-dotnet" id="Snippet1":::
905+
:::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.enum.getvalues/vb/getvalues1.vb" id="Snippet1":::
906906
907907
The <xref:System.Enum.GetValues%2A> method returns an array that contains a value for each member of the `enumType` enumeration. If multiple members have the same value, the returned array includes duplicate values. In this case, calling the <xref:System.Enum.GetName%2A> method with each value in the returned array does not restore the unique names assigned to members that have duplicate values. To retrieve all the names of enumeration members successfully, call the <xref:System.Enum.GetNames%2A> method.
908908
@@ -921,9 +921,9 @@
921921
## Examples
922922
The following example illustrates the use of <xref:System.Enum.GetValues%2A>.
923923
924-
[!code-cpp[enumgetvalues#1](~/samples/snippets/cpp/VS_Snippets_CLR/enumgetvalues/CPP/EnumGetValues.cpp#1)]
925-
[!code-csharp[enumgetvalues#1](~/samples/snippets/csharp/VS_Snippets_CLR/enumgetvalues/CS/EnumGetValues.cs#1)]
926-
[!code-vb[enumgetvalues#1](~/samples/snippets/visualbasic/VS_Snippets_CLR/enumgetvalues/VB/EnumGetValues.vb#1)]
924+
:::code language="cpp" source="~/samples/snippets/cpp/VS_Snippets_CLR/enumgetvalues/CPP/EnumGetValues.cpp" id="Snippet1":::
925+
:::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR/enumgetvalues/CS/EnumGetValues.cs" interactive="try-dotnet" id="Snippet1":::
926+
:::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR/enumgetvalues/VB/EnumGetValues.vb" id="Snippet1":::
927927
928928
]]></format>
929929
</remarks>

0 commit comments

Comments
 (0)