Skip to content

Commit 999c71a

Browse files
Merge pull request #88 from ProfessionalCSharp/dotnet6
.NET 6 and C# 10 updates
2 parents d47d728 + 1e5975e commit 999c71a

File tree

2,082 files changed

+298987
-138320
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,082 files changed

+298987
-138320
lines changed

1_CS/Arrays/.vscode/launch.json

Lines changed: 0 additions & 28 deletions
This file was deleted.

1_CS/Arrays/.vscode/tasks.json

Lines changed: 0 additions & 16 deletions
This file was deleted.

1_CS/Arrays/ArrayPoolSample/ArrayPoolSample.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net5.0</TargetFramework>
5+
<TargetFramework>net6.0</TargetFramework>
66
<Nullable>enable</Nullable>
7+
<ImplicitUsings>enable</ImplicitUsings>
78
</PropertyGroup>
89

910
<PropertyGroup>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
global using System.Buffers;

1_CS/Arrays/ArrayPoolSample/Program.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
using System;
2-
using System.Buffers;
3-
4-
for (int i = 0; i < 10; i++)
1+
for (int i = 0; i < 10; i++)
52
{
63
int arrayLength = (i + 1) << 10;
74
int[] arr = ArrayPool<int>.Shared.Rent(arrayLength);

1_CS/Arrays/BitArraySample/BitArrayExtensions.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
using System.Collections;
2-
using System.Text;
3-
4-
public static class BitArrayExtensions
1+
public static class BitArrayExtensions
52
{
63
public static string FormatString(this BitArray bits)
74
{

1_CS/Arrays/BitArraySample/BitArraySample.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net5.0</TargetFramework>
5+
<TargetFramework>net6.0</TargetFramework>
66
<Nullable>enable</Nullable>
7+
<ImplicitUsings>enable</ImplicitUsings>
78
</PropertyGroup>
89

910
</Project>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
global using System.Collections;
2+
global using System.Text;

1_CS/Arrays/BitArraySample/Program.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
using System;
2-
using System.Collections;
3-
4-
BitArray bits1 = new(9);
1+
BitArray bits1 = new(9);
52
bits1.SetAll(true);
63
bits1.Set(1, false);
74
bits1[5] = false;

1_CS/Arrays/BitVectorSample/BinaryExtensions.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
using System;
2-
using System.Linq;
3-
4-
public static class BinaryExtensions
1+
public static class BinaryExtensions
52
{
63
public static string AddSeparators(this string number) =>
74
number.Length <= 4 ? number :

1_CS/Arrays/BitVectorSample/BitVectorSample.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net5.0</TargetFramework>
5+
<TargetFramework>net6.0</TargetFramework>
66
<Nullable>enable</Nullable>
7+
<ImplicitUsings>enable</ImplicitUsings>
78
</PropertyGroup>
89

910
<ItemGroup>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
global using System.Collections.Specialized;

1_CS/Arrays/BitVectorSample/Program.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
using System;
2-
using System.Collections.Specialized;
3-
4-
// create a mask using the CreateMask method
1+
// create a mask using the CreateMask method
52
BitVector32 bits1 = new();
63
int bit1 = BitVector32.CreateMask();
74
int bit2 = BitVector32.CreateMask(bit1);

1_CS/Arrays/IndicesAndRanges/IndicesAndRanges.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net5.0</TargetFramework>
5+
<TargetFramework>net6.0</TargetFramework>
66
<Nullable>enable</Nullable>
7+
<ImplicitUsings>enable</ImplicitUsings>
78
</PropertyGroup>
89

910
</Project>

1_CS/Arrays/IndicesAndRanges/MyCollection.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
using System;
2-
using System.Linq;
3-
4-
public class MyCollection
1+
public class MyCollection
52
{
63
private int[] _array = Enumerable.Range(1, 100).ToArray();
74

1_CS/Arrays/IndicesAndRanges/Program.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using System;
2-
3-
int[] data = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
1+
int[] data = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
42

53
// indices and the hat operator
64

@@ -54,6 +52,3 @@ void ShowRange(string title, int[] data)
5452
int n = coll[^20];
5553
Console.WriteLine($"Item from the collection: {n}");
5654
ShowRange("Using custom collection", coll[45..^40]);
57-
58-
59-

1_CS/Arrays/Readme.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,8 @@ For code comments and issues please check [Professional C#'s GitHub Repository](
1616

1717
Please check my blog [csharp.christiannagel.com](https://csharp.christiannagel.com "csharp.christiannagel.com") for additional information for topics covered in the book.
1818

19-
Thank you!
19+
Thank you!
20+
21+
## Updates with C# 10
22+
23+
See [Updates with C# 10](../../Dotnet6Updates.md)

1_CS/Arrays/SimpleArrays/Program.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using System;
2-
3-
SimpleArrays();
1+
SimpleArrays();
42
TwoDim();
53
ThreeDim();
64
Jagged();
@@ -10,10 +8,11 @@
108

119
void CopyArrays()
1210
{
13-
Person[] beatles = {
14-
new ("John", "Lennon"),
15-
new ("Paul", "McCartney")
16-
};
11+
Person[] beatles =
12+
{
13+
new ("John", "Lennon"),
14+
new ("Paul", "McCartney")
15+
};
1716

1817
Person[] beatlesClone = (Person[])beatles.Clone();
1918
}

1_CS/Arrays/SimpleArrays/SimpleArrays.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net5.0</TargetFramework>
5+
<TargetFramework>net6.0</TargetFramework>
66
<Nullable>enable</Nullable>
7+
<ImplicitUsings>enable</ImplicitUsings>
78
</PropertyGroup>
89

910
</Project>

1_CS/Arrays/SortingSample/Person.cs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
1-
using System;
1+
namespace Wrox.ProCSharp.Arrays;
22

3-
namespace Wrox.ProCSharp.Arrays
3+
public record Person(string FirstName, string LastName) : IComparable<Person>
44
{
5-
public record Person(string FirstName, string LastName) : IComparable<Person>
5+
public int CompareTo(Person? other)
66
{
7-
public int CompareTo(Person? other)
8-
{
9-
if (other == null) throw new ArgumentNullException("other");
10-
11-
int result = LastName.CompareTo(other.LastName);
12-
if (result == 0)
13-
{
14-
result = FirstName.CompareTo(other.FirstName);
15-
}
7+
if (other == null) throw new ArgumentNullException("other");
168

17-
return result;
9+
int result = LastName.CompareTo(other.LastName);
10+
if (result == 0)
11+
{
12+
result = FirstName.CompareTo(other.FirstName);
1813
}
1914

20-
public override string ToString() => $"{FirstName} {LastName}";
15+
return result;
2116
}
17+
18+
public override string ToString() => $"{FirstName} {LastName}";
2219
}
Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,31 @@
1-
using System;
2-
using System.Collections.Generic;
1+
namespace Wrox.ProCSharp.Arrays;
2+
public enum PersonCompareType
3+
{
4+
FirstName,
5+
LastName
6+
}
37

4-
namespace Wrox.ProCSharp.Arrays
8+
public class PersonComparer : IComparer<Person>
59
{
6-
public enum PersonCompareType
7-
{
8-
FirstName,
9-
LastName
10-
}
10+
private PersonCompareType _compareType;
1111

12-
public class PersonComparer : IComparer<Person>
13-
{
14-
private PersonCompareType _compareType;
12+
public PersonComparer(PersonCompareType compareType) =>
13+
_compareType = compareType;
1514

16-
public PersonComparer(PersonCompareType compareType) =>
17-
_compareType = compareType;
15+
#region IComparer<Person> Members
16+
public int Compare(Person? x, Person? y)
17+
{
18+
if (x is null && y is null) return 0;
19+
if (x is null) return 1;
20+
if (y is null) return -1;
1821

19-
#region IComparer<Person> Members
20-
public int Compare(Person? x, Person? y)
22+
return _compareType switch
2123
{
22-
if (x is null && y is null) return 0;
23-
if (x is null) return 1;
24-
if (y is null) return -1;
25-
26-
return _compareType switch
27-
{
28-
PersonCompareType.FirstName => x.FirstName.CompareTo(y.FirstName),
29-
PersonCompareType.LastName => x.LastName.CompareTo(y.LastName),
30-
_ => throw new ArgumentException("unexpected compare type")
31-
};
32-
}
33-
34-
#endregion
24+
PersonCompareType.FirstName => x.FirstName.CompareTo(y.FirstName),
25+
PersonCompareType.LastName => x.LastName.CompareTo(y.LastName),
26+
_ => throw new ArgumentException("unexpected compare type")
27+
};
3528
}
29+
30+
#endregion
3631
}

0 commit comments

Comments
 (0)