Skip to content

Commit 1a1e8af

Browse files
authored
update samples for interactive csharp (#971)
Update the samples and snippets for the Math.Round page to conform to the snippet limitation on C# interactive.
1 parent 57c3ac9 commit 1a1e8af

File tree

8 files changed

+82
-82
lines changed

8 files changed

+82
-82
lines changed
Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//<snippet1>
21
// This example demonstrates the Math.Round() method in conjunction
32
// with the MidpointRounding enumeration.
43
using System;
@@ -7,49 +6,50 @@ class Sample
76
{
87
public static void Main()
98
{
9+
//<snippet1>
1010
decimal result = 0.0m;
1111
decimal posValue = 3.45m;
1212
decimal negValue = -3.45m;
1313

14-
// By default, round a positive and a negative value to the nearest even number.
15-
// The precision of the result is 1 decimal place.
14+
// By default, round a positive and a negative value to the nearest even number.
15+
// The precision of the result is 1 decimal place.
1616

1717
result = Math.Round(posValue, 1);
1818
Console.WriteLine("{0,4} = Math.Round({1,5}, 1)", result, posValue);
1919
result = Math.Round(negValue, 1);
2020
Console.WriteLine("{0,4} = Math.Round({1,5}, 1)", result, negValue);
2121
Console.WriteLine();
2222

23-
// Round a positive value to the nearest even number, then to the nearest number away from zero.
24-
// The precision of the result is 1 decimal place.
23+
// Round a positive value to the nearest even number, then to the nearest number away from zero.
24+
// The precision of the result is 1 decimal place.
2525

2626
result = Math.Round(posValue, 1, MidpointRounding.ToEven);
2727
Console.WriteLine("{0,4} = Math.Round({1,5}, 1, MidpointRounding.ToEven)", result, posValue);
2828
result = Math.Round(posValue, 1, MidpointRounding.AwayFromZero);
2929
Console.WriteLine("{0,4} = Math.Round({1,5}, 1, MidpointRounding.AwayFromZero)", result, posValue);
3030
Console.WriteLine();
3131

32-
// Round a negative value to the nearest even number, then to the nearest number away from zero.
33-
// The precision of the result is 1 decimal place.
32+
// Round a negative value to the nearest even number, then to the nearest number away from zero.
33+
// The precision of the result is 1 decimal place.
3434

3535
result = Math.Round(negValue, 1, MidpointRounding.ToEven);
3636
Console.WriteLine("{0,4} = Math.Round({1,5}, 1, MidpointRounding.ToEven)", result, negValue);
3737
result = Math.Round(negValue, 1, MidpointRounding.AwayFromZero);
3838
Console.WriteLine("{0,4} = Math.Round({1,5}, 1, MidpointRounding.AwayFromZero)", result, negValue);
3939
Console.WriteLine();
40-
}
41-
}
42-
/*
43-
This code example produces the following results:
40+
/*
41+
This code example produces the following results:
4442
45-
3.4 = Math.Round( 3.45, 1)
46-
-3.4 = Math.Round(-3.45, 1)
43+
3.4 = Math.Round( 3.45, 1)
44+
-3.4 = Math.Round(-3.45, 1)
4745
48-
3.4 = Math.Round( 3.45, 1, MidpointRounding.ToEven)
49-
3.5 = Math.Round( 3.45, 1, MidpointRounding.AwayFromZero)
46+
3.4 = Math.Round( 3.45, 1, MidpointRounding.ToEven)
47+
3.5 = Math.Round( 3.45, 1, MidpointRounding.AwayFromZero)
5048
51-
-3.4 = Math.Round(-3.45, 1, MidpointRounding.ToEven)
52-
-3.5 = Math.Round(-3.45, 1, MidpointRounding.AwayFromZero)
49+
-3.4 = Math.Round(-3.45, 1, MidpointRounding.ToEven)
50+
-3.5 = Math.Round(-3.45, 1, MidpointRounding.AwayFromZero)
5351
54-
*/
55-
//</snippet1>
52+
*/
53+
//</snippet1>
54+
}
55+
}

snippets/csharp/VS_Snippets_CLR_Classic/classic Math.Round Example/CS/source.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
// <Snippet1>
21
using System;
32

43
class Program
54
{
65
static void Main()
76
{
7+
// <Snippet1>
88
Console.WriteLine("Classic Math.Round in CSharp");
99
Console.WriteLine(Math.Round(4.4)); // 4
1010
Console.WriteLine(Math.Round(4.5)); // 4
1111
Console.WriteLine(Math.Round(4.6)); // 5
1212
Console.WriteLine(Math.Round(5.5)); // 6
13+
// </Snippet1>
1314
}
1415
}
15-
// </Snippet1>
1616

1717

1818

snippets/csharp/VS_Snippets_CLR_System/system.math.round.overload/cs/mean1.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
// <Snippet2>
21
using System;
32

43
public class Example
54
{
65
public static void Main()
76
{
7+
// <Snippet2>
88
decimal[] values = { 1.15m, 1.25m, 1.35m, 1.45m, 1.55m, 1.65m };
99
decimal sum = 0;
1010

@@ -27,10 +27,10 @@ public static void Main()
2727
sum += Math.Round(value, 1, MidpointRounding.ToEven);
2828

2929
Console.WriteLine("ToEven: {0:N2}", sum/values.Length);
30+
// The example displays the following output:
31+
// True mean: 1.40
32+
// AwayFromZero: 1.45
33+
// ToEven: 1.40
34+
// </Snippet2>
3035
}
3136
}
32-
// The example displays the following output:
33-
// True mean: 1.40
34-
// AwayFromZero: 1.45
35-
// ToEven: 1.40
36-
// </Snippet2>
Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
1-
// <Snippet5>
21
using System;
32

43
public class Example
54
{
65
public static void Main()
76
{
7+
// <Snippet5>
88
Console.WriteLine("{0,-10} {1,-10} {2,-10} {3,-15}", "Value", "Default",
99
"ToEven", "AwayFromZero");
1010
for (decimal value = 12.0m; value <= 13.0m; value += 0.1m)
1111
Console.WriteLine("{0,-10} {1,-10} {2,-10} {3,-15}",
1212
value, Math.Round(value),
1313
Math.Round(value, MidpointRounding.ToEven),
1414
Math.Round(value, MidpointRounding.AwayFromZero));
15+
// The example displays the following output:
16+
// Value Default ToEven AwayFromZero
17+
// 12 12 12 12
18+
// 12.1 12 12 12
19+
// 12.2 12 12 12
20+
// 12.3 12 12 12
21+
// 12.4 12 12 12
22+
// 12.5 12 12 13
23+
// 12.6 13 13 13
24+
// 12.7 13 13 13
25+
// 12.8 13 13 13
26+
// 12.9 13 13 13
27+
// 13.0 13 13 13
28+
// </Snippet5>
1529
}
1630
}
17-
// The example displays the following output:
18-
// Value Default ToEven AwayFromZero
19-
// 12 12 12 12
20-
// 12.1 12 12 12
21-
// 12.2 12 12 12
22-
// 12.3 12 12 12
23-
// 12.4 12 12 12
24-
// 12.5 12 12 13
25-
// 12.6 13 13 13
26-
// 12.7 13 13 13
27-
// 12.8 13 13 13
28-
// 12.9 13 13 13
29-
// 13.0 13 13 13
30-
// </Snippet5>

snippets/csharp/VS_Snippets_CLR_System/system.math.round.overload/cs/mpr.cs

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

43
class Sample
54
{
65
public static void Main()
76
{
7+
// <snippet4>
88
double posValue = 3.45;
99
double negValue = -3.45;
1010

@@ -29,15 +29,15 @@ public static void Main()
2929
result = Math.Round(negValue, 1, MidpointRounding.AwayFromZero);
3030
Console.WriteLine("{0,4} = Math.Round({1,5}, 1, MidpointRounding.AwayFromZero)\n",
3131
result, negValue);
32+
// The example displays the following output:
33+
// 3.4 = Math.Round( 3.45, 1)
34+
// -3.4 = Math.Round(-3.45, 1)
35+
//
36+
// 3.4 = Math.Round( 3.45, 1, MidpointRounding.ToEven)
37+
// 3.5 = Math.Round( 3.45, 1, MidpointRounding.AwayFromZero)
38+
//
39+
// -3.4 = Math.Round(-3.45, 1, MidpointRounding.ToEven)
40+
// -3.5 = Math.Round(-3.45, 1, MidpointRounding.AwayFromZero)
41+
// </Snippet4>
3242
}
3343
}
34-
// The example displays the following output:
35-
// 3.4 = Math.Round( 3.45, 1)
36-
// -3.4 = Math.Round(-3.45, 1)
37-
//
38-
// 3.4 = Math.Round( 3.45, 1, MidpointRounding.ToEven)
39-
// 3.5 = Math.Round( 3.45, 1, MidpointRounding.AwayFromZero)
40-
//
41-
// -3.4 = Math.Round(-3.45, 1, MidpointRounding.ToEven)
42-
// -3.5 = Math.Round(-3.45, 1, MidpointRounding.AwayFromZero)
43-
// </Snippet4>
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
// <Snippet3>
21
using System;
32

43
public class Sample {
54
static void Main() {
5+
// <Snippet3>
66
Console.WriteLine(Math.Round(3.44m, 1));
77
Console.WriteLine(Math.Round(3.45m, 1));
88
Console.WriteLine(Math.Round(3.46m, 1));
@@ -11,15 +11,15 @@ static void Main() {
1111
Console.WriteLine(Math.Round(4.34m, 1));
1212
Console.WriteLine(Math.Round(4.35m, 1));
1313
Console.WriteLine(Math.Round(4.36m, 1));
14+
// The example displays the following output:
15+
// 3.4
16+
// 3.4
17+
// 3.5
18+
//
19+
// 4.3
20+
// 4.4
21+
// 4.4
22+
// </Snippet3>
1423
}
1524
}
16-
// The example displays the following output:
17-
// 3.4
18-
// 3.4
19-
// 3.5
20-
//
21-
// 4.3
22-
// 4.4
23-
// 4.4
24-
// </Snippet3>
2525

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
// <Snippet3>
21
using System;
32

43
public class Example
54
{
65
public static void Main()
76
{
7+
// <Snippet3>
88
double[] values = { 2.125, 2.135, 2.145, 3.125, 3.135, 3.145 };
99
foreach (double value in values)
1010
Console.WriteLine("{0} --> {1}", value,
1111
Math.Round(value, 2, MidpointRounding.AwayFromZero));
1212

13+
// The example displays the following output:
14+
// 2.125 --> 2.13
15+
// 2.135 --> 2.13
16+
// 2.145 --> 2.15
17+
// 3.125 --> 3.13
18+
// 3.135 --> 3.14
19+
// 3.145 --> 3.15
20+
// </Snippet3>
1321
}
1422
}
15-
// The example displays the following output:
16-
// 2.125 --> 2.13
17-
// 2.135 --> 2.13
18-
// 2.145 --> 2.15
19-
// 3.125 --> 3.13
20-
// 3.135 --> 3.14
21-
// 3.145 --> 3.15
22-
// </Snippet3>
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
// <Snippet6>
21
using System;
32

43
class Example
54
{
65
static void Main()
76
{
7+
// <Snippet6>
88
for (decimal value = 4.2m; value <= 4.8m; value+=.1m )
99
Console.WriteLine("{0} --> {1}", value, Math.Round(value));
10+
// The example displays the following output:
11+
// 4.2 --> 4
12+
// 4.3 --> 4
13+
// 4.4 --> 4
14+
// 4.5 --> 4
15+
// 4.6 --> 5
16+
// 4.7 --> 5
17+
// 4.8 --> 5
18+
// </Snippet6>
1019
}
1120
}
12-
// The example displays the following output:
13-
// 4.2 --> 4
14-
// 4.3 --> 4
15-
// 4.4 --> 4
16-
// 4.5 --> 4
17-
// 4.6 --> 5
18-
// 4.7 --> 5
19-
// 4.8 --> 5
20-
// </Snippet6>

0 commit comments

Comments
 (0)