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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 0 additions & 1 deletion
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
}
Lines changed: 5 additions & 5 deletions
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

Lines changed: 1 addition & 1 deletion
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>
Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 8 deletions
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}");

0 commit comments

Comments
 (0)