Skip to content

Commit 8c2c56a

Browse files
.net 8 - object-orientation #203
1 parent 2c91972 commit 8c2c56a

File tree

18 files changed

+27
-50
lines changed

18 files changed

+27
-50
lines changed

1_CS/ObjectOrientation/AbstractClasses/AbstractClasses.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net7.0</TargetFramework>
5+
<TargetFramework>net8.0</TargetFramework>
66
<Nullable>enable</Nullable>
77
<ImplicitUsings>enable</ImplicitUsings>
88
</PropertyGroup>

1_CS/ObjectOrientation/AbstractClasses/Shape.cs

-1
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,3 @@ public virtual void Move(Position newPosition)
3535

3636
public abstract Shape Clone();
3737
}
38-

1_CS/ObjectOrientation/DefaultInterfaceMethods/DefaultInterfaceMethods.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net7.0</TargetFramework>
5+
<TargetFramework>net8.0</TargetFramework>
66
<Nullable>enable</Nullable>
77
<ImplicitUsings>enable</ImplicitUsings>
88
</PropertyGroup>

1_CS/ObjectOrientation/DefaultInterfaceMethods/Program.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
IEnumerableEx<string> names = new MyCollection<string> { "James", "Jack", "Jochen", "Sebastian", "Lewis", "Juan" };
66

7-
var jNames = names.Where(n => n.StartsWith("J"));
7+
var jNames = names.Where(n => n.StartsWith('J'));
88
foreach (var name in jNames)
99
{
1010
Console.WriteLine(name);

1_CS/ObjectOrientation/GenericTypes/GenericTypes.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net7.0</TargetFramework>
5+
<TargetFramework>net8.0</TargetFramework>
66
<Nullable>enable</Nullable>
77
<ImplicitUsings>enable</ImplicitUsings>
88
</PropertyGroup>

1_CS/ObjectOrientation/GenericTypes/LinkedList.cs

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ public LinkedListNode<T> AddLast(T node)
1515
else
1616
{
1717
newNode.Prev = Last;
18-
LinkedListNode<T> previous = Last;
1918
Last.Next = newNode;
2019
Last = newNode;
2120
}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
LinkedList<int> list1 = new();
1+
LinkedList<int> list1 = [];
22
list1.AddLast(1);
33
list1.AddLast(3);
44
list1.AddLast(2);
@@ -9,15 +9,15 @@
99
}
1010
Console.WriteLine();
1111

12-
LinkedList<string> list2 = new();
12+
LinkedList<string> list2 = [];
1313
list2.AddLast("two");
1414
list2.AddLast("four");
1515
list2.AddLast("six");
1616

1717
// show the last
1818
Console.WriteLine(list2.Last);
1919

20-
LinkedList<(int, int)> list3 = new();
20+
LinkedList<(int, int)> list3 = [];
2121
list3.AddLast((1, 2));
2222
list3.AddLast((3, 4));
2323
foreach (var item in list3)
@@ -26,12 +26,12 @@
2626
}
2727
Console.WriteLine();
2828

29-
LinkedList<Person> list4 = new();
29+
LinkedList<Person> list4 = [];
3030
list4.AddLast(new Person("Stephanie", "Nagel"));
3131
list4.AddLast(new Person("Matthias", "Nagel"));
3232
list4.AddLast(new Person("Katharina", "Nagel"));
3333

3434
// show the first
3535
Console.WriteLine(list4.First);
3636

37-
public record Person(string FirstName, string LastName);
37+
public record class Person(string FirstName, string LastName);

1_CS/ObjectOrientation/GenericTypesWithConstraints/GenericTypesWithConstraints.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net7.0</TargetFramework>
5+
<TargetFramework>net8.0</TargetFramework>
66
<Nullable>enable</Nullable>
77
<ImplicitUsings>enable</ImplicitUsings>
88
</PropertyGroup>
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
LinkedList<Person> list4 = new();
1+
LinkedList<Person> list4 = [];
22
list4.AddLast(new Person("Stephanie", "Nagel", "Mrs"));
33
list4.AddLast(new Person("Matthias", "Nagel", "Mr"));
44
list4.AddLast(new Person("Katharina", "Nagel", "Mrs"));
55

66
// show the first
77
Console.WriteLine(list4.First);
88

9-
public record Person(string FirstName, string LastName, string Title) : ITitle { }
9+
public record class Person(string FirstName, string LastName, string Title) : ITitle { }

1_CS/ObjectOrientation/InheritanceWithConstructors/ConcreteShapes.cs

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
public class Rectangle : Shape
1+
public class Rectangle(int x, int y, int width, int height) : Shape(x, y, width, height)
22
{
3-
public Rectangle(int x, int y, int width, int height)
4-
: base(x, y, width, height) { }
5-
63
protected override void DisplayShape()
74
{
85
Console.WriteLine($"Rectangle at position {Position} with size {Size}");
@@ -11,11 +8,8 @@ protected override void DisplayShape()
118
public override Rectangle Clone() => new(Position.X, Position.Y, Size.Width, Size.Height);
129
}
1310

14-
public class Ellipse : Shape
11+
public class Ellipse(int x, int y, int width, int height) : Shape(x, y, width, height)
1512
{
16-
public Ellipse(int x, int y, int width, int height)
17-
: base(x, y, width, height) { }
18-
1913
protected override void DisplayShape()
2014
{
2115
Console.WriteLine($"Ellipse at position {Position} with size {Size}");

1_CS/ObjectOrientation/InheritanceWithConstructors/InheritanceWithConstructors.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net7.0</TargetFramework>
5+
<TargetFramework>net8.0</TargetFramework>
66
<Nullable>enable</Nullable>
77
<ImplicitUsings>enable</ImplicitUsings>
88
</PropertyGroup>

1_CS/ObjectOrientation/InheritanceWithConstructors/Shape.cs

+3-9
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,10 @@ public class Size
3535
public override string ToString() => $"Width: {Width}, Height: {Height}";
3636
}
3737

38-
public abstract class Shape
38+
public abstract class Shape(int x, int y, int width, int height)
3939
{
40-
public Shape(int x, int y, int width, int height)
41-
{
42-
Position = new Position(x, y);
43-
Size = new Size(width, height);
44-
}
45-
46-
public Position Position { get; }
47-
public virtual Size Size { get; }
40+
public Position Position { get; } = new Position(x, y);
41+
public virtual Size Size { get; } = new Size(width, height);
4842

4943
public void Draw() => DisplayShape();
5044

1_CS/ObjectOrientation/RecordsInheritance/RecordsInheritance.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net7.0</TargetFramework>
5+
<TargetFramework>net8.0</TargetFramework>
66
<Nullable>enable</Nullable>
77
<ImplicitUsings>enable</ImplicitUsings>
88
</PropertyGroup>

1_CS/ObjectOrientation/UsingInterfaces/ConcreteShapes.cs

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
1-
public class Rectangle : Shape
1+
public class Rectangle(ILogger logger) : Shape(logger)
22
{
3-
public Rectangle(ILogger logger) : base(logger) { }
4-
53
protected override void DisplayShape()
64
{
75
Logger.Log($"Rectangle at position {Position} with size {Size}");
86
}
97
}
108

11-
public class Ellipse : Shape
9+
public class Ellipse(ILogger logger) : Shape(logger)
1210
{
13-
public Ellipse(ILogger logger) : base(logger) { }
14-
1511
protected override void DisplayShape()
1612
{
1713
Logger.Log($"Ellipse at position {Position} with size {Size}");

1_CS/ObjectOrientation/UsingInterfaces/Program.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ void SortWithIComparable()
77
Person p2 = new("Graham", "Hill");
88
Person p3 = new("Damon", "Hill");
99

10-
Person[] people = { p1, p2, p3 };
10+
Person[] people = [p1, p2, p3];
1111
Array.Sort(people);
1212
foreach (var p in people)
1313
{

1_CS/ObjectOrientation/UsingInterfaces/Shape.cs

+2-7
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,9 @@
22

33
public record Size(int Width, int Height);
44

5-
public abstract class Shape
5+
public abstract class Shape(ILogger logger)
66
{
7-
public Shape(ILogger logger)
8-
{
9-
Logger = logger;
10-
}
11-
12-
protected ILogger Logger { get; }
7+
protected ILogger Logger { get; } = logger;
138
public Position? Position { get; init; }
149
public Size? Size { get; init; }
1510

1_CS/ObjectOrientation/UsingInterfaces/UsingInterfaces.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net7.0</TargetFramework>
6-
<Nullable>enable</Nullable>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<Nullable>enable</Nullable>
77
<ImplicitUsings>enable</ImplicitUsings>
88
</PropertyGroup>
99

1_CS/ObjectOrientation/VirtualMethods/VirtualMethods.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net7.0</TargetFramework>
5+
<TargetFramework>net8.0</TargetFramework>
66
<Nullable>enable</Nullable>
77
<ImplicitUsings>enable</ImplicitUsings>
88
</PropertyGroup>

0 commit comments

Comments
 (0)