Skip to content

Commit c5fd03a

Browse files
authored
Batch 30 sample fixes (dotnet#5418)
* Batch 30 sample fixes * restore some changes * Make VB match C# version
1 parent ea6728e commit c5fd03a

File tree

8 files changed

+115
-97
lines changed
  • samples/snippets

8 files changed

+115
-97
lines changed

samples/snippets/cpp/VS_Snippets_CLR/GetCustomAttributes/CPP/custattrs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,8 @@ namespace CustAttrs5CS
251251

252252
/*
253253
* Output:
254+
* Parameter args for method ParamArrayAndDesc has the ParamArray attribute.
254255
* Parameter args for method ParamArrayAndDesc has a description attribute.
255256
* The description is: "This argument is a ParamArray"
256-
* Parameter args for method ParamArrayAndDesc has the ParamArray attribute.
257257
*/
258258
// </Snippet5>

samples/snippets/csharp/VS_Snippets_CLR/GetCustomAttributes/CS/ca5.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ static void Main(string[] args) {
4848

4949
/*
5050
* Output:
51+
* Parameter args for method ParamArrayAndDesc has the ParamArray attribute.
5152
* Parameter args for method ParamArrayAndDesc has a description attribute.
5253
* The description is: "This argument is a ParamArray"
53-
* Parameter args for method ParamArrayAndDesc has the ParamArray attribute.
5454
*/
5555
// </Snippet5>

samples/snippets/csharp/VS_Snippets_CLR_System/system.Single.Parse/CS/parse3.cs

Lines changed: 54 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,69 +7,87 @@ public class Example
77
public static void Main()
88
{
99
// Define an array of string values.
10-
string[] values = { " 987.654E-2", " 987,654E-2", "(98765,43210)",
10+
string[] values = { " 987.654E-2", " 987,654E-2", "(98765,43210)",
1111
"9,876,543.210", "9.876.543,210", "98_76_54_32,19" };
1212
// Create a custom culture based on the invariant culture.
1313
CultureInfo ci = new CultureInfo("");
1414
ci.NumberFormat.NumberGroupSizes = new int[] { 2 };
1515
ci.NumberFormat.NumberGroupSeparator = "_";
16-
16+
1717
// Define an array of format providers.
1818
CultureInfo[] providers = { new CultureInfo("en-US"),
19-
new CultureInfo("nl-NL"), ci };
20-
19+
new CultureInfo("nl-NL"), ci };
20+
2121
// Define an array of styles.
2222
NumberStyles[] styles = { NumberStyles.Currency, NumberStyles.Float };
23-
23+
2424
// Iterate the array of format providers.
2525
foreach (CultureInfo provider in providers)
2626
{
27-
Console.WriteLine("Parsing using the {0} culture:",
27+
Console.WriteLine("Parsing using the {0} culture:",
2828
provider.Name == String.Empty ? "Invariant" : provider.Name);
2929
// Parse each element in the array of string values.
3030
foreach (string value in values)
3131
{
3232
foreach (NumberStyles style in styles)
3333
{
3434
try {
35-
float number = Single.Parse(value, style, provider);
36-
Console.WriteLine(" {0} ({1}) -> {2}",
35+
float number = Single.Parse(value, style, provider);
36+
Console.WriteLine(" {0} ({1}) -> {2}",
3737
value, style, number);
3838
}
3939
catch (FormatException) {
4040
Console.WriteLine(" '{0}' is invalid using {1}.", value, style);
4141
}
4242
catch (OverflowException) {
4343
Console.WriteLine(" '{0}' is out of the range of a Single.", value);
44-
}
45-
}
46-
}
44+
}
45+
}
46+
}
4747
Console.WriteLine();
4848
}
49-
}
50-
}
49+
}
50+
}
5151
// The example displays the following output:
52-
// Parsing using the en-US culture:
53-
// The format of // 987.654E-2// is invalid.
54-
// The format of // 987,654E-2// is invalid.
55-
// (98765,43210) (Currency) -> -9.876543E+09
56-
// 9,876,543.210 (Currency) -> 9876543
57-
// The format of '9.876.543,210// is invalid.
58-
// The format of '98_76_54_32,19// is invalid.
59-
//
60-
// Parsing using the nl-NL culture:
61-
// The format of // 987.654E-2// is invalid.
62-
// The format of // 987,654E-2// is invalid.
63-
// (98765,43210) (Currency) -> -98765.43
64-
// The format of '9,876,543.210// is invalid.
65-
// 9.876.543,210 (Currency) -> 9876543
66-
// The format of '98_76_54_32,19// is invalid.
67-
//
68-
// Parsing using the Invariant culture:
69-
// The format of // 987.654E-2// is invalid.
70-
// The format of // 987,654E-2// is invalid.
71-
// (98765,43210) (Currency) -> -9.876543E+09
72-
// 9,876,543.210 (Currency) -> 9876543
73-
// The format of '9.876.543,210// is invalid.
74-
// 98_76_54_32,19 (Currency) -> 9.876543E+09
52+
// Parsing using the en-US culture:
53+
// ' 987.654E-2' is invalid using Currency.
54+
// 987.654E-2 (Float) -> 9.87654
55+
// ' 987,654E-2' is invalid using Currency.
56+
// ' 987,654E-2' is invalid using Float.
57+
// (98765,43210) (Currency) -> -9.876543E+09
58+
// '(98765,43210)' is invalid using Float.
59+
// 9,876,543.210 (Currency) -> 9876543
60+
// '9,876,543.210' is invalid using Float.
61+
// '9.876.543,210' is invalid using Currency.
62+
// '9.876.543,210' is invalid using Float.
63+
// '98_76_54_32,19' is invalid using Currency.
64+
// '98_76_54_32,19' is invalid using Float.
65+
//
66+
// Parsing using the nl-NL culture:
67+
// ' 987.654E-2' is invalid using Currency.
68+
// ' 987.654E-2' is invalid using Float.
69+
// ' 987,654E-2' is invalid using Currency.
70+
// 987,654E-2 (Float) -> 9.87654
71+
// (98765,43210) (Currency) -> -98765.43
72+
// '(98765,43210)' is invalid using Float.
73+
// '9,876,543.210' is invalid using Currency.
74+
// '9,876,543.210' is invalid using Float.
75+
// 9.876.543,210 (Currency) -> 9876543
76+
// '9.876.543,210' is invalid using Float.
77+
// '98_76_54_32,19' is invalid using Currency.
78+
// '98_76_54_32,19' is invalid using Float.
79+
//
80+
// Parsing using the Invariant culture:
81+
// ' 987.654E-2' is invalid using Currency.
82+
// 987.654E-2 (Float) -> 9.87654
83+
// ' 987,654E-2' is invalid using Currency.
84+
// ' 987,654E-2' is invalid using Float.
85+
// (98765,43210) (Currency) -> -9.876543E+09
86+
// '(98765,43210)' is invalid using Float.
87+
// 9,876,543.210 (Currency) -> 9876543
88+
// '9,876,543.210' is invalid using Float.
89+
// '9.876.543,210' is invalid using Currency.
90+
// '9.876.543,210' is invalid using Float.
91+
// 98_76_54_32,19 (Currency) -> 9.876543E+09
92+
// '98_76_54_32,19' is invalid using Float.
7593
// </Snippet4>

samples/snippets/csharp/VS_Snippets_CLR_System/system.array.rank/cs/rank1.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public static void Main()
1818
}
1919
}
2020
// The example displays the following output:
21-
// System.Int32[]: 1 dimension
22-
// System.Int32[,]: 2 dimension
23-
// System.Int32[][]: 1 dimension
21+
// System.Int32[]: 1 dimension(s)
22+
// System.Int32[,]: 2 dimension(s)
23+
// System.Int32[][]: 1 dimension(s)
2424
// </Snippet1>

samples/snippets/csharp/VS_Snippets_CLR_System/system.single.tryparse/cs/tryparse1.cs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,40 +14,40 @@ private static void DefaultTryParse()
1414
// <Snippet1>
1515
string value;
1616
float number;
17-
17+
1818
// Parse a floating-point value with a thousands separator.
1919
value = "1,643.57";
2020
if (Single.TryParse(value, out number))
2121
Console.WriteLine(number);
2222
else
23-
Console.WriteLine("Unable to parse '{0}'.", value);
24-
25-
// Parse a floating-point value with a currency symbol and a
23+
Console.WriteLine("Unable to parse '{0}'.", value);
24+
25+
// Parse a floating-point value with a currency symbol and a
2626
// thousands separator.
2727
value = "$1,643.57";
2828
if (Single.TryParse(value, out number))
2929
Console.WriteLine(number);
3030
else
31-
Console.WriteLine("Unable to parse '{0}'.", value);
32-
31+
Console.WriteLine("Unable to parse '{0}'.", value);
32+
3333
// Parse value in exponential notation.
3434
value = "-1.643e6";
3535
if (Single.TryParse(value, out number))
3636
Console.WriteLine(number);
3737
else
38-
Console.WriteLine("Unable to parse '{0}'.", value);
39-
38+
Console.WriteLine("Unable to parse '{0}'.", value);
39+
4040
// Parse a negative integer value.
4141
value = "-168934617882109132";
4242
if (Single.TryParse(value, out number))
4343
Console.WriteLine(number);
4444
else
45-
Console.WriteLine("Unable to parse '{0}'.", value);
45+
Console.WriteLine("Unable to parse '{0}'.", value);
4646
// The example displays the following output:
4747
// 1643.57
4848
// Unable to parse '$1,643.57'.
4949
// -164300
50-
// -1.68934617882109E+17
50+
// -1.689346E+17
5151
// </Snippet1>
5252
}
5353

@@ -58,34 +58,34 @@ private static void TryParseWithConstraints()
5858
System.Globalization.NumberStyles style;
5959
System.Globalization.CultureInfo culture;
6060
float number;
61-
61+
6262
// Parse currency value using en-GB culture.
6363
value = "£1,097.63";
64-
style = System.Globalization.NumberStyles.Number |
64+
style = System.Globalization.NumberStyles.Number |
6565
System.Globalization.NumberStyles.AllowCurrencySymbol;
6666
culture = System.Globalization.CultureInfo.CreateSpecificCulture("en-GB");
6767
if (Single.TryParse(value, style, culture, out number))
6868
Console.WriteLine("Converted '{0}' to {1}.", value, number);
6969
else
7070
Console.WriteLine("Unable to convert '{0}'.", value);
71-
71+
7272
value = "1345,978";
7373
style = System.Globalization.NumberStyles.AllowDecimalPoint;
7474
culture = System.Globalization.CultureInfo.CreateSpecificCulture("fr-FR");
7575
if (Single.TryParse(value, style, culture, out number))
7676
Console.WriteLine("Converted '{0}' to {1}.", value, number);
7777
else
7878
Console.WriteLine("Unable to convert '{0}'.", value);
79-
79+
8080
value = "1.345,978";
81-
style = System.Globalization.NumberStyles.AllowDecimalPoint |
81+
style = System.Globalization.NumberStyles.AllowDecimalPoint |
8282
System.Globalization.NumberStyles.AllowThousands;
8383
culture = System.Globalization.CultureInfo.CreateSpecificCulture("es-ES");
8484
if (Single.TryParse(value, style, culture, out number))
8585
Console.WriteLine("Converted '{0}' to {1}.", value, number);
8686
else
8787
Console.WriteLine("Unable to convert '{0}'.", value);
88-
88+
8989
value = "1 345,978";
9090
if (Single.TryParse(value, style, culture, out number))
9191
Console.WriteLine("Converted '{0}' to {1}.", value, number);
@@ -96,6 +96,6 @@ private static void TryParseWithConstraints()
9696
// Converted '1345,978' to 1345.978.
9797
// Converted '1.345,978' to 1345.978.
9898
// Unable to convert '1 345,978'.
99-
// </Snippet2>
99+
// </Snippet2>
100100
}
101101
}

samples/snippets/visualbasic/VS_Snippets_CLR/GetCustomAttributes/VB/ca5.vb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,23 @@ Module DemoModule
2626
' Convert the attribute to access its data.
2727
Dim paAttr As ParamArrayAttribute = _
2828
CType(attr, ParamArrayAttribute)
29-
Console.WriteLine("Parameter {0} has the " + _
30-
"ParamArray attribute.", pInfo(0).Name)
29+
Console.WriteLine("Parameter {0} for method {1} has the " + _
30+
"ParamArray attribute.", pInfo(0).Name, mInfo.Name)
3131
' Check for the Description attribute.
3232
ElseIf TypeOf attr Is DescriptionAttribute Then
3333
' Convert the attribute to access its data.
3434
Dim descAttr As DescriptionAttribute = _
3535
CType(attr, DescriptionAttribute)
36-
Console.WriteLine("Parameter {0} has a description " + _
37-
"attribute. The description is:", pInfo(0).Name)
36+
Console.WriteLine("Parameter {0} for method {1} has a description " + _
37+
"attribute. The description is:", pInfo(0).Name, mInfo.Name)
3838
Console.WriteLine(descAttr.Description)
3939
End If
4040
Next
4141
End Sub
4242
End Module
4343

4444
' Output:
45-
' Parameter args has a description attribute. The description is:
45+
' Parameter args for method ParamArrayAndDesc has the ParamArray attribute.
46+
' Parameter args for method ParamArrayAndDesc has a description attribute. The description is:
4647
' This argument is a ParamArray
47-
' Parameter args has the ParamArray attribute.
4848
' </Snippet5>

samples/snippets/visualbasic/VS_Snippets_CLR_System/system.array.rank/vb/rank1.vb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,21 @@ Option Strict On
44
' <Snippet1>
55
Module Example
66
Public Sub Main()
7-
Dim array1(9) As Integer
8-
Dim array2(9,2) As Integer
9-
Dim array3(9)() As Integer
10-
11-
Console.WriteLine("{0}: {1} dimension(s)",
7+
Dim array1(9) As Integer
8+
Dim array2(9,2) As Integer
9+
Dim array3(9)() As Integer
10+
11+
Console.WriteLine("{0}: {1} dimension(s)",
1212
array1.ToString(), array1.Rank)
13-
Console.WriteLine("{0}: {1} dimension(s)",
13+
Console.WriteLine("{0}: {1} dimension(s)",
1414
array2.ToString(), array2.Rank)
15-
Console.WriteLine("{0}: {1} dimension(s)",
15+
Console.WriteLine("{0}: {1} dimension(s)",
1616
array3.ToString(), array3.Rank)
1717
End Sub
1818
End Module
1919
' The example displays the following output:
20-
' System.Int32[]: 1 dimension
21-
' System.Int32[,]: 2 dimension
22-
' System.Int32[][]: 1 dimension
20+
' System.Int32[]: 1 dimension(s)
21+
' System.Int32[,]: 2 dimension(s)
22+
' System.Int32[][]: 1 dimension(s)
2323
' </Snippet1>
2424

0 commit comments

Comments
 (0)