Skip to content

Commit 587b29e

Browse files
authored
Reinstate supplemental remarks (System/A-H) (#12700)
1 parent c1e270b commit 587b29e

256 files changed

Lines changed: 13286 additions & 179 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: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// <Snippet4>
2+
using System;
3+
using System.Reflection;
4+
5+
[assembly: AssemblyVersion("1.0.0.0")]
6+
7+
public static class StringLibrary1
8+
{
9+
public static int SubstringStartsAt(string fullString, string substr)
10+
{
11+
return fullString.IndexOf(substr, StringComparison.Ordinal);
12+
}
13+
}
14+
// </Snippet4>
15+
16+
namespace App
17+
{
18+
// <Snippet5>
19+
using System;
20+
21+
public class Example1
22+
{
23+
public static void Main()
24+
{
25+
string value = "The archaeologist";
26+
string substring = "archæ";
27+
int position = StringLibrary1.SubstringStartsAt(value, substring);
28+
if (position >= 0)
29+
Console.WriteLine($"'{substring}' found in '{value}' starting at position {position}");
30+
else
31+
Console.WriteLine($"'{substring}' not found in '{value}'");
32+
}
33+
}
34+
// The example displays the following output:
35+
// 'archæ' not found in 'The archaeologist'
36+
// </Snippet5>
37+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Library</OutputType>
5+
<TargetFramework>net10.0</TargetFramework>
6+
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
7+
</PropertyGroup>
8+
9+
</Project>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// <Snippet6>
2+
using System;
3+
using System.Reflection;
4+
5+
[assembly: AssemblyVersion("2.0.0.0")]
6+
7+
public static class StringLibrary2
8+
{
9+
public static int SubstringStartsAt(string fullString, string substr)
10+
{
11+
return fullString.IndexOf(substr, StringComparison.CurrentCulture);
12+
}
13+
}
14+
// </Snippet6>
15+
16+
namespace App
17+
{
18+
// <Snippet7>
19+
using System;
20+
21+
public class Example2
22+
{
23+
public static void Main()
24+
{
25+
string value = "The archaeologist";
26+
string substring = "archæ";
27+
int position = StringLibrary2.SubstringStartsAt(value, substring);
28+
if (position >= 0)
29+
Console.WriteLine($"'{substring}' found in '{value}' starting at position {position}");
30+
else
31+
Console.WriteLine($"'{substring}' not found in '{value}'");
32+
}
33+
}
34+
// The example displays the following output:
35+
// 'archæ' found in 'The archaeologist' starting at position 4
36+
// </Snippet7>
37+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Library</OutputType>
5+
<TargetFramework>net10.0</TargetFramework>
6+
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
7+
</PropertyGroup>
8+
9+
</Project>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// <Snippet8>
2+
using System;
3+
using System.Reflection;
4+
5+
[assembly: AssemblyVersion("2.0.0.0")]
6+
7+
public static class StringLibrary
8+
{
9+
public static int SubstringStartsAt(string fullString, string substr)
10+
{
11+
bool flag;
12+
if (AppContext.TryGetSwitch("StringLibrary.DoNotUseCultureSensitiveComparison", out flag) && flag == true)
13+
return fullString.IndexOf(substr, StringComparison.Ordinal);
14+
else
15+
return fullString.IndexOf(substr, StringComparison.CurrentCulture);
16+
}
17+
}
18+
// </Snippet8>
19+
20+
namespace App
21+
{
22+
// <Snippet9>
23+
using System;
24+
25+
public class Example
26+
{
27+
public static void Main()
28+
{
29+
string value = "The archaeologist";
30+
string substring = "archæ";
31+
int position = StringLibrary.SubstringStartsAt(value, substring);
32+
if (position >= 0)
33+
Console.WriteLine($"'{substring}' found in '{value}' starting at position {position}");
34+
else
35+
Console.WriteLine($"'{substring}' not found in '{value}'");
36+
}
37+
}
38+
// The example displays the following output:
39+
// 'archæ' found in 'The archaeologist' starting at position 4
40+
// </Snippet9>
41+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Library</OutputType>
5+
<TargetFramework>net10.0</TargetFramework>
6+
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
7+
</PropertyGroup>
8+
9+
</Project>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Library</OutputType>
5+
<TargetFramework>net10.0</TargetFramework>
6+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
7+
</PropertyGroup>
8+
9+
</Project>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// <Snippet1>
2+
using System;
3+
4+
public class Example1
5+
{
6+
public static void Main()
7+
{
8+
bool[] flags = { true, false };
9+
foreach (var flag in flags)
10+
{
11+
// Get binary representation of flag.
12+
Byte value = BitConverter.GetBytes(flag)[0];
13+
Console.WriteLine($"Original value: {flag}");
14+
Console.WriteLine($"Binary value: {value} ({GetBinaryString(value)})");
15+
// Restore the flag from its binary representation.
16+
bool newFlag = BitConverter.ToBoolean(new Byte[] { value }, 0);
17+
Console.WriteLine($"Restored value: {newFlag}{Environment.NewLine}");
18+
}
19+
}
20+
21+
private static string GetBinaryString(Byte value)
22+
{
23+
string retVal = Convert.ToString(value, 2);
24+
return new string('0', 8 - retVal.Length) + retVal;
25+
}
26+
}
27+
// The example displays the following output:
28+
// Original value: True
29+
// Binary value: 1 (00000001)
30+
// Restored value: True
31+
//
32+
// Original value: False
33+
// Binary value: 0 (00000000)
34+
// Restored value: False
35+
// </Snippet1>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// <Snippet6>
2+
using System;
3+
4+
public class Example2
5+
{
6+
public static void Main()
7+
{
8+
Byte byteValue = 12;
9+
Console.WriteLine(Convert.ToBoolean(byteValue));
10+
Byte byteValue2 = 0;
11+
Console.WriteLine(Convert.ToBoolean(byteValue2));
12+
int intValue = -16345;
13+
Console.WriteLine(Convert.ToBoolean(intValue));
14+
long longValue = 945;
15+
Console.WriteLine(Convert.ToBoolean(longValue));
16+
SByte sbyteValue = -12;
17+
Console.WriteLine(Convert.ToBoolean(sbyteValue));
18+
double dblValue = 0;
19+
Console.WriteLine(Convert.ToBoolean(dblValue));
20+
float sngValue = .0001f;
21+
Console.WriteLine(Convert.ToBoolean(sngValue));
22+
}
23+
}
24+
// The example displays the following output:
25+
// True
26+
// False
27+
// True
28+
// True
29+
// True
30+
// False
31+
// True
32+
// </Snippet6>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// <Snippet8>
2+
using System;
3+
4+
public class Example3
5+
{
6+
public static void Main()
7+
{
8+
bool flag = true;
9+
10+
byte byteValue;
11+
byteValue = Convert.ToByte(flag);
12+
Console.WriteLine($"{flag} -> {byteValue}");
13+
14+
sbyte sbyteValue;
15+
sbyteValue = Convert.ToSByte(flag);
16+
Console.WriteLine($"{flag} -> {sbyteValue}");
17+
18+
double dblValue;
19+
dblValue = Convert.ToDouble(flag);
20+
Console.WriteLine($"{flag} -> {dblValue}");
21+
22+
int intValue;
23+
intValue = Convert.ToInt32(flag);
24+
Console.WriteLine($"{flag} -> {intValue}");
25+
}
26+
}
27+
// The example displays the following output:
28+
// True -> 1
29+
// True -> 1
30+
// True -> 1
31+
// True -> 1
32+
// </Snippet8>

0 commit comments

Comments
 (0)