Skip to content

Commit c1e270b

Browse files
authored
Reinstate supplemental remarks (System/S-Z) (#12702)
1 parent d9e0962 commit c1e270b

300 files changed

Lines changed: 10552 additions & 343 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// SByte_Ctor1.cpp : Defines the entry point for the console application.
2+
//
3+
4+
//#include "stdafx.h"
5+
6+
// <Snippet4>
7+
using namespace System;
8+
9+
void main()
10+
{
11+
char chars[] = { 'a', 'b', 'c', 'd', '\x00' };
12+
13+
char* charPtr = chars;
14+
String^ value = gcnew String(charPtr);
15+
16+
Console::WriteLine(value);
17+
}
18+
// The example displays the following output:
19+
// abcd
20+
// </Snippet4>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Example9.Run();
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFrameworks>net10.0</TargetFrameworks>
6+
</PropertyGroup>
7+
8+
</Project>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// <Snippet5>
2+
using System;
3+
4+
public class Example9
5+
{
6+
public static void Run()
7+
{
8+
double value1 = 1 / 3.0;
9+
float sValue2 = 1 / 3.0f;
10+
double value2 = (double)sValue2;
11+
Console.WriteLine($"{value1:R} = {value2:R}: {value1.Equals(value2)}");
12+
}
13+
}
14+
15+
// The example displays the following output:
16+
// 0.33333333333333331 = 0.3333333432674408: False
17+
// </Snippet5>

snippets/csharp/System/Double/Overview/source.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ public double Celsius {
213213
}
214214
//</snippet4>
215215
}
216+
216217
namespace Snippets5 {
217218
//<snippet5>
218219
public class Temperature {
@@ -257,6 +258,7 @@ public double Celsius {
257258
}
258259
//</snippet5>
259260
}
261+
260262
namespace Snippets6 {
261263
//<snippet6>
262264
public class Temperature {
@@ -301,6 +303,7 @@ public double Celsius {
301303
}
302304
//</snippet6>
303305
}
306+
304307
namespace Snippets7 {
305308
//<snippet7>
306309
public class Temperature {
@@ -345,6 +348,7 @@ public double Celsius {
345348
}
346349
//</snippet7>
347350
}
351+
348352
namespace Snippets8 {
349353
//<snippet8>
350354
public class Temperature {
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// <Snippet2>
2+
using System;
3+
4+
public class TestFormatter
5+
{
6+
public static void Main()
7+
{
8+
int acctNumber = 79203159;
9+
Console.WriteLine(String.Format(new CustomerFormatter(), "{0}", acctNumber));
10+
Console.WriteLine(String.Format(new CustomerFormatter(), "{0:G}", acctNumber));
11+
Console.WriteLine(String.Format(new CustomerFormatter(), "{0:S}", acctNumber));
12+
Console.WriteLine(String.Format(new CustomerFormatter(), "{0:P}", acctNumber));
13+
try {
14+
Console.WriteLine(String.Format(new CustomerFormatter(), "{0:X}", acctNumber));
15+
}
16+
catch (FormatException e) {
17+
Console.WriteLine(e.Message);
18+
}
19+
}
20+
}
21+
22+
public class CustomerFormatter : IFormatProvider, ICustomFormatter
23+
{
24+
public object GetFormat(Type formatType)
25+
{
26+
if (formatType == typeof(ICustomFormatter))
27+
return this;
28+
else
29+
return null;
30+
}
31+
32+
public string Format(string format,
33+
object arg,
34+
IFormatProvider formatProvider)
35+
{
36+
if (! this.Equals(formatProvider))
37+
{
38+
return null;
39+
}
40+
else
41+
{
42+
if (String.IsNullOrEmpty(format))
43+
format = "G";
44+
45+
string customerString = arg.ToString();
46+
if (customerString.Length < 8)
47+
customerString = customerString.PadLeft(8, '0');
48+
49+
format = format.ToUpper();
50+
switch (format)
51+
{
52+
case "G":
53+
return customerString.Substring(0, 1) + "-" +
54+
customerString.Substring(1, 5) + "-" +
55+
customerString.Substring(6);
56+
case "S":
57+
return customerString.Substring(0, 1) + "/" +
58+
customerString.Substring(1, 5) + "/" +
59+
customerString.Substring(6);
60+
case "P":
61+
return customerString.Substring(0, 1) + "." +
62+
customerString.Substring(1, 5) + "." +
63+
customerString.Substring(6);
64+
default:
65+
throw new FormatException(
66+
String.Format("The '{0}' format specifier is not supported.", format));
67+
}
68+
}
69+
}
70+
}
71+
// The example displays the following output:
72+
// 7-92031-59
73+
// 7-92031-59
74+
// 7/92031/59
75+
// 7.92031.59
76+
// The 'X' format specifier is not supported.
77+
// </Snippet2>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Library</OutputType>
5+
<TargetFramework>net10.0</TargetFramework>
6+
</PropertyGroup>
7+
8+
</Project>

snippets/csharp/System/FormatException/Overview/example2.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// <Snippet2>
22
using System;
33

4-
public class Example
4+
public class FormatExample2
55
{
66
public enum TemperatureScale
77
{ Celsius, Fahrenheit, Kelvin }

snippets/csharp/System/FormatException/Overview/example3.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System;
22

3-
public class Example
3+
public class FormatExample3
44
{
55
public static void Main()
66
{

snippets/csharp/System/FormatException/Overview/format4.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
using System;
22

3-
public class Example
3+
public class FormatExample4
44
{
5-
public static void Main()
5+
public static void Run()
66
{
77
// <Snippet4>
88
string formatString = " {0,10} ({0,8:X8})\n" +
99
"And {1,10} ({1,8:X8})\n" +
1010
" = {2,10} ({2,8:X8})";
1111
int value1 = 16932;
1212
int value2 = 15421;
13-
string result = String.Format(formatString,
13+
string result = string.Format(formatString,
1414
value1, value2, value1 & value2);
1515
Console.WriteLine(result);
16+
1617
// The example displays the following output:
1718
// 16932 (00004224)
1819
// And 15421 (00003C3D)

0 commit comments

Comments
 (0)