Skip to content

Commit 316b3ca

Browse files
WilliamAntonRohmBillWagner
authored andcommitted
Math.xml samples -- updating for Try .NET (#1875)
* updating for Try .NET * updating for interpolated strings
1 parent 55239ca commit 316b3ca

File tree

11 files changed

+240
-234
lines changed

11 files changed

+240
-234
lines changed
Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,62 @@
1-
//<snippet1>
2-
// This example demonstrates Math.Max()
1+
// This example demonstrates Math.Max()
32
using System;
43

54
class Sample
65
{
76
public static void Main()
87
{
9-
string str = "{0}: The greater of {1,3} and {2,3} is {3}.";
10-
string nl = Environment.NewLine;
11-
12-
byte xByte1 = 1, xByte2 = 51;
13-
short xShort1 = -2, xShort2 = 52;
14-
int xInt1 = -3, xInt2 = 53;
15-
long xLong1 = -4, xLong2 = 54;
16-
float xSingle1 = 5.0f, xSingle2 = 55.0f;
17-
double xDouble1 = 6.0, xDouble2 = 56.0;
18-
Decimal xDecimal1 = 7m, xDecimal2 = 57m;
19-
20-
// The following types are not CLS-compliant.
21-
sbyte xSbyte1 = 101, xSbyte2 = 111;
22-
ushort xUshort1 = 102, xUshort2 = 112;
23-
uint xUint1 = 103, xUint2 = 113;
24-
ulong xUlong1 = 104, xUlong2 = 114;
25-
26-
Console.WriteLine("{0}Display the greater of two values:{0}", nl);
27-
Console.WriteLine(str, "Byte ", xByte1, xByte2, Math.Max(xByte1, xByte2));
28-
Console.WriteLine(str, "Int16 ", xShort1, xShort2, Math.Max(xShort1, xShort2));
29-
Console.WriteLine(str, "Int32 ", xInt1, xInt2, Math.Max(xInt1, xInt2));
30-
Console.WriteLine(str, "Int64 ", xLong1, xLong2, Math.Max(xLong1, xLong2));
31-
Console.WriteLine(str, "Single ", xSingle1, xSingle2, Math.Max(xSingle1, xSingle2));
32-
Console.WriteLine(str, "Double ", xDouble1, xDouble2, Math.Max(xDouble1, xDouble2));
33-
Console.WriteLine(str, "Decimal", xDecimal1, xDecimal2, Math.Max(xDecimal1, xDecimal2));
34-
//
35-
Console.WriteLine("{0}The following types are not CLS-compliant.{0}", nl);
36-
Console.WriteLine(str, "SByte ", xSbyte1, xSbyte2, Math.Max(xSbyte1, xSbyte2));
37-
Console.WriteLine(str, "UInt16 ", xUshort1, xUshort2, Math.Max(xUshort1, xUshort2));
38-
Console.WriteLine(str, "UInt32 ", xUint1, xUint2, Math.Max(xUint1, xUint2));
39-
Console.WriteLine(str, "UInt64 ", xUlong1, xUlong2, Math.Max(xUlong1, xUlong2));
8+
//<snippet1>
9+
string str = "{0}: The greater of {1,3} and {2,3} is {3}.";
10+
11+
byte xByte1 = 1, xByte2 = 51;
12+
short xShort1 = -2, xShort2 = 52;
13+
int xInt1 = -3, xInt2 = 53;
14+
long xLong1 = -4, xLong2 = 54;
15+
float xSingle1 = 5.0f, xSingle2 = 55.0f;
16+
double xDouble1 = 6.0, xDouble2 = 56.0;
17+
Decimal xDecimal1 = 7m, xDecimal2 = 57m;
18+
19+
// The following types are not CLS-compliant.
20+
sbyte xSbyte1 = 101, xSbyte2 = 111;
21+
ushort xUshort1 = 102, xUshort2 = 112;
22+
uint xUint1 = 103, xUint2 = 113;
23+
ulong xUlong1 = 104, xUlong2 = 114;
24+
25+
Console.WriteLine("Display the greater of two values:\n");
26+
Console.WriteLine(str, "Byte ", xByte1, xByte2, Math.Max(xByte1, xByte2));
27+
Console.WriteLine(str, "Int16 ", xShort1, xShort2, Math.Max(xShort1, xShort2));
28+
Console.WriteLine(str, "Int32 ", xInt1, xInt2, Math.Max(xInt1, xInt2));
29+
Console.WriteLine(str, "Int64 ", xLong1, xLong2, Math.Max(xLong1, xLong2));
30+
Console.WriteLine(str, "Single ", xSingle1, xSingle2, Math.Max(xSingle1, xSingle2));
31+
Console.WriteLine(str, "Double ", xDouble1, xDouble2, Math.Max(xDouble1, xDouble2));
32+
Console.WriteLine(str, "Decimal", xDecimal1, xDecimal2, Math.Max(xDecimal1, xDecimal2));
33+
34+
Console.WriteLine("\nThe following types are not CLS-compliant.\n");
35+
Console.WriteLine(str, "SByte ", xSbyte1, xSbyte2, Math.Max(xSbyte1, xSbyte2));
36+
Console.WriteLine(str, "UInt16 ", xUshort1, xUshort2, Math.Max(xUshort1, xUshort2));
37+
Console.WriteLine(str, "UInt32 ", xUint1, xUint2, Math.Max(xUint1, xUint2));
38+
Console.WriteLine(str, "UInt64 ", xUlong1, xUlong2, Math.Max(xUlong1, xUlong2));
39+
40+
/*
41+
This example produces the following results:
42+
43+
Display the greater of two values:
44+
45+
Byte : The greater of 1 and 51 is 51.
46+
Int16 : The greater of -2 and 52 is 52.
47+
Int32 : The greater of -3 and 53 is 53.
48+
Int64 : The greater of -4 and 54 is 54.
49+
Single : The greater of 5 and 55 is 55.
50+
Double : The greater of 6 and 56 is 56.
51+
Decimal: The greater of 7 and 57 is 57.
52+
53+
(The following types are not CLS-compliant.)
54+
55+
SByte : The greater of 101 and 111 is 111.
56+
UInt16 : The greater of 102 and 112 is 112.
57+
UInt32 : The greater of 103 and 113 is 113.
58+
UInt64 : The greater of 104 and 114 is 114.
59+
*/
60+
//</snippet1>
4061
}
4162
}
42-
/*
43-
This example produces the following results:
44-
45-
Display the greater of two values:
46-
47-
Byte : The greater of 1 and 51 is 51.
48-
Int16 : The greater of -2 and 52 is 52.
49-
Int32 : The greater of -3 and 53 is 53.
50-
Int64 : The greater of -4 and 54 is 54.
51-
Single : The greater of 5 and 55 is 55.
52-
Double : The greater of 6 and 56 is 56.
53-
Decimal: The greater of 7 and 57 is 57.
54-
55-
(The following types are not CLS-compliant.)
56-
57-
SByte : The greater of 101 and 111 is 111.
58-
UInt16 : The greater of 102 and 112 is 112.
59-
UInt32 : The greater of 103 and 113 is 113.
60-
UInt64 : The greater of 104 and 114 is 114.
61-
*/
62-
//</snippet1>
Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,62 @@
1-
//<snippet1>
2-
// This example demonstrates Math.Min()
1+
// This example demonstrates Math.Min()
32
using System;
43

54
class Sample
65
{
76
public static void Main()
87
{
9-
string str = "{0}: The lesser of {1,3} and {2,3} is {3}.";
10-
string nl = Environment.NewLine;
11-
12-
byte xByte1 = 1, xByte2 = 51;
13-
short xShort1 = -2, xShort2 = 52;
14-
int xInt1 = -3, xInt2 = 53;
15-
long xLong1 = -4, xLong2 = 54;
16-
float xSingle1 = 5.0f, xSingle2 = 55.0f;
17-
double xDouble1 = 6.0, xDouble2 = 56.0;
18-
Decimal xDecimal1 = 7m, xDecimal2 = 57m;
19-
20-
// The following types are not CLS-compliant.
21-
sbyte xSbyte1 = 101, xSbyte2 = 111;
22-
ushort xUshort1 = 102, xUshort2 = 112;
23-
uint xUint1 = 103, xUint2 = 113;
24-
ulong xUlong1 = 104, xUlong2 = 114;
25-
26-
Console.WriteLine("{0}Display the lesser of two values:{0}", nl);
27-
Console.WriteLine(str, "Byte ", xByte1, xByte2, Math.Min(xByte1, xByte2));
28-
Console.WriteLine(str, "Int16 ", xShort1, xShort2, Math.Min(xShort1, xShort2));
29-
Console.WriteLine(str, "Int32 ", xInt1, xInt2, Math.Min(xInt1, xInt2));
30-
Console.WriteLine(str, "Int64 ", xLong1, xLong2, Math.Min(xLong1, xLong2));
31-
Console.WriteLine(str, "Single ", xSingle1, xSingle2, Math.Min(xSingle1, xSingle2));
32-
Console.WriteLine(str, "Double ", xDouble1, xDouble2, Math.Min(xDouble1, xDouble2));
33-
Console.WriteLine(str, "Decimal", xDecimal1, xDecimal2, Math.Min(xDecimal1, xDecimal2));
34-
//
35-
Console.WriteLine("{0}The following types are not CLS-compliant:{0}", nl);
36-
Console.WriteLine(str, "SByte ", xSbyte1, xSbyte2, Math.Min(xSbyte1, xSbyte2));
37-
Console.WriteLine(str, "UInt16 ", xUshort1, xUshort2, Math.Min(xUshort1, xUshort2));
38-
Console.WriteLine(str, "UInt32 ", xUint1, xUint2, Math.Min(xUint1, xUint2));
39-
Console.WriteLine(str, "UInt64 ", xUlong1, xUlong2, Math.Min(xUlong1, xUlong2));
8+
//<snippet1>
9+
string str = "{0}: The lesser of {1,3} and {2,3} is {3}.";
10+
11+
byte xByte1 = 1, xByte2 = 51;
12+
short xShort1 = -2, xShort2 = 52;
13+
int xInt1 = -3, xInt2 = 53;
14+
long xLong1 = -4, xLong2 = 54;
15+
float xSingle1 = 5.0f, xSingle2 = 55.0f;
16+
double xDouble1 = 6.0, xDouble2 = 56.0;
17+
Decimal xDecimal1 = 7m, xDecimal2 = 57m;
18+
19+
// The following types are not CLS-compliant.
20+
sbyte xSbyte1 = 101, xSbyte2 = 111;
21+
ushort xUshort1 = 102, xUshort2 = 112;
22+
uint xUint1 = 103, xUint2 = 113;
23+
ulong xUlong1 = 104, xUlong2 = 114;
24+
25+
Console.WriteLine("Display the lesser of two values:\n");
26+
Console.WriteLine(str, "Byte ", xByte1, xByte2, Math.Min(xByte1, xByte2));
27+
Console.WriteLine(str, "Int16 ", xShort1, xShort2, Math.Min(xShort1, xShort2));
28+
Console.WriteLine(str, "Int32 ", xInt1, xInt2, Math.Min(xInt1, xInt2));
29+
Console.WriteLine(str, "Int64 ", xLong1, xLong2, Math.Min(xLong1, xLong2));
30+
Console.WriteLine(str, "Single ", xSingle1, xSingle2, Math.Min(xSingle1, xSingle2));
31+
Console.WriteLine(str, "Double ", xDouble1, xDouble2, Math.Min(xDouble1, xDouble2));
32+
Console.WriteLine(str, "Decimal", xDecimal1, xDecimal2, Math.Min(xDecimal1, xDecimal2));
33+
34+
Console.WriteLine("\nThe following types are not CLS-compliant:\n");
35+
Console.WriteLine(str, "SByte ", xSbyte1, xSbyte2, Math.Min(xSbyte1, xSbyte2));
36+
Console.WriteLine(str, "UInt16 ", xUshort1, xUshort2, Math.Min(xUshort1, xUshort2));
37+
Console.WriteLine(str, "UInt32 ", xUint1, xUint2, Math.Min(xUint1, xUint2));
38+
Console.WriteLine(str, "UInt64 ", xUlong1, xUlong2, Math.Min(xUlong1, xUlong2));
39+
40+
/*
41+
This example produces the following results:
42+
43+
Display the lesser of two values:
44+
45+
Byte : The lesser of 1 and 51 is 1.
46+
Int16 : The lesser of -2 and 52 is -2.
47+
Int32 : The lesser of -3 and 53 is -3.
48+
Int64 : The lesser of -4 and 54 is -4.
49+
Single : The lesser of 5 and 55 is 5.
50+
Double : The lesser of 6 and 56 is 6.
51+
Decimal: The lesser of 7 and 57 is 7.
52+
53+
The following types are not CLS-compliant:
54+
55+
SByte : The lesser of 101 and 111 is 101.
56+
UInt16 : The lesser of 102 and 112 is 102.
57+
UInt32 : The lesser of 103 and 113 is 103.
58+
UInt64 : The lesser of 104 and 114 is 104.
59+
*/
60+
//</snippet1>
4061
}
4162
}
42-
/*
43-
This example produces the following results:
44-
45-
Display the lesser of two values:
46-
47-
Byte : The lesser of 1 and 51 is 1.
48-
Int16 : The lesser of -2 and 52 is -2.
49-
Int32 : The lesser of -3 and 53 is -3.
50-
Int64 : The lesser of -4 and 54 is -4.
51-
Single : The lesser of 5 and 55 is 5.
52-
Double : The lesser of 6 and 56 is 6.
53-
Decimal: The lesser of 7 and 57 is 7.
54-
55-
The following types are not CLS-compliant:
56-
57-
SByte : The lesser of 101 and 111 is 101.
58-
UInt16 : The lesser of 102 and 112 is 102.
59-
UInt32 : The lesser of 103 and 113 is 103.
60-
UInt64 : The lesser of 104 and 114 is 104.
61-
*/
62-
//</snippet1>
Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
1-
// <Snippet1>
2-
using System;
1+
using System;
32

43
public class Example
54
{
65
public static void Main()
76
{
7+
// <Snippet1>
88
decimal[] decimals = { Decimal.MaxValue, 12.45M, 0M, -19.69M,
99
Decimal.MinValue };
1010
foreach (decimal value in decimals)
11-
Console.WriteLine("Abs({0}) = {1}", value, Math.Abs(value));
11+
Console.WriteLine($"Abs({value}) = {Math.Abs(value)}");
1212

13+
// The example displays the following output:
14+
// Abs(79228162514264337593543950335) = 79228162514264337593543950335
15+
// Abs(12.45) = 12.45
16+
// Abs(0) = 0
17+
// Abs(-19.69) = 19.69
18+
// Abs(-79228162514264337593543950335) = 79228162514264337593543950335
19+
// </Snippet1>
1320
}
1421
}
15-
// The example displays the following output:
16-
// Abs(79228162514264337593543950335) = 79228162514264337593543950335
17-
// Abs(12.45) = 12.45
18-
// Abs(0) = 0
19-
// Abs(-19.69) = 19.69
20-
// Abs(-79228162514264337593543950335) = 79228162514264337593543950335
21-
// </Snippet1>
22-
Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
1-
// <Snippet2>
2-
using System;
1+
using System;
32

43
public class Example
54
{
65
public static void Main()
76
{
7+
// <Snippet2>
88
double[] doubles = { Double.MaxValue, 16.354e-17, 15.098123, 0,
99
-19.069713, -15.058e18, Double.MinValue };
1010
foreach (double value in doubles)
11-
Console.WriteLine("Abs({0}) = {1}", value, Math.Abs(value));
11+
Console.WriteLine($"Abs({value}) = {Math.Abs(value)}");
12+
13+
// The example displays the following output:
14+
// Abs(1.79769313486232E+308) = 1.79769313486232E+308
15+
// Abs(1.6354E-16) = 1.6354E-16
16+
// Abs(15.098123) = 15.098123
17+
// Abs(0) = 0
18+
// Abs(-19.069713) = 19.069713
19+
// Abs(-1.5058E+19) = 1.5058E+19
20+
// Abs(-1.79769313486232E+308) = 1.79769313486232E+308
21+
// </Snippet2>
1222
}
1323
}
14-
// The example displays the following output:
15-
// Abs(1.79769313486232E+308) = 1.79769313486232E+308
16-
// Abs(1.6354E-16) = 1.6354E-16
17-
// Abs(15.098123) = 15.098123
18-
// Abs(0) = 0
19-
// Abs(-19.069713) = 19.069713
20-
// Abs(-1.5058E+19) = 1.5058E+19
21-
// Abs(-1.79769313486232E+308) = 1.79769313486232E+308
22-
// </Snippet2>
2324

snippets/csharp/VS_Snippets_CLR_System/system.Math.Abs/cs/abs3.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
1-
// <Snippet3>
2-
using System;
1+
using System;
32

43
public class Example
54
{
65
public static void Main()
76
{
7+
// <Snippet3>
88
short[] values = { Int16.MaxValue, 10328, 0, -1476, Int16.MinValue };
99
foreach (short value in values)
1010
{
1111
try {
12-
Console.WriteLine("Abs({0}) = {1}", value, Math.Abs(value));
12+
Console.WriteLine($"Abs({value}) = {Math.Abs(value)}");
1313
}
1414
catch (OverflowException) {
1515
Console.WriteLine("Unable to calculate the absolute value of {0}.",
1616
value);
1717
}
1818
}
19+
20+
// The example displays the following output:
21+
// Abs(32767) = 32767
22+
// Abs(10328) = 10328
23+
// Abs(0) = 0
24+
// Abs(-1476) = 1476
25+
// Unable to calculate the absolute value of -32768.
26+
// </Snippet3>
1927
}
2028
}
21-
// The example displays the following output:
22-
// Abs(32767) = 32767
23-
// Abs(10328) = 10328
24-
// Abs(0) = 0
25-
// Abs(-1476) = 1476
26-
// Unable to calculate the absolute value of -32768.
27-
// </Snippet3>

snippets/csharp/VS_Snippets_CLR_System/system.Math.Abs/cs/abs4.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
1-
// <Snippet4>
2-
using System;
1+
using System;
32

43
public class Example
54
{
65
public static void Main()
76
{
7+
// <Snippet4>
88
int[] values = { Int32.MaxValue, 16921, 0, -804128, Int32.MinValue };
99
foreach (int value in values)
1010
{
1111
try {
12-
Console.WriteLine("Abs({0}) = {1}", value, Math.Abs(value));
12+
Console.WriteLine($"Abs({value}) = {Math.Abs(value)}");
1313
}
1414
catch (OverflowException) {
1515
Console.WriteLine("Unable to calculate the absolute value of {0}.",
1616
value);
1717
}
1818
}
19+
20+
// The example displays the following output:
21+
// Abs(2147483647) = 2147483647
22+
// Abs(16921) = 16921
23+
// Abs(0) = 0
24+
// Abs(-804128) = 804128
25+
// Unable to calculate the absolute value of -2147483648.
26+
// </Snippet4>
1927
}
2028
}
21-
// The example displays the following output:
22-
// Abs(2147483647) = 2147483647
23-
// Abs(16921) = 16921
24-
// Abs(0) = 0
25-
// Abs(-804128) = 804128
26-
// Unable to calculate the absolute value of -2147483648.
27-
// </Snippet4>

0 commit comments

Comments
 (0)