Skip to content

Commit 69fb5a8

Browse files
CopilotBillWagner
andcommitted
Address feedback: use expression-bodied members, update syntax, and target .NET 9
Co-authored-by: BillWagner <[email protected]>
1 parent c366f66 commit 69fb5a8

File tree

3 files changed

+6
-18
lines changed

3 files changed

+6
-18
lines changed

docs/csharp/language-reference/keywords/abstract.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Abstract classes can contain both abstract members (which have no implementation
1919

2020
The following example demonstrates an abstract class that contains both implemented methods and abstract members:
2121

22-
[!code-csharp[AbstractWithImplemented](snippets/abstract/Program.cs#snippet1)]
22+
:::code language="csharp" source="snippets/abstract/Program.cs" id="snippet1":::
2323

2424
In this example, the `Vehicle` abstract class provides:
2525
- **Implemented members**: `GetInfo()` method, `StartEngine()` method, and constructor - these provide common functionality for all vehicles

docs/csharp/language-reference/keywords/snippets/abstract/Program.cs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,10 @@ public Vehicle(string brand)
1010
}
1111

1212
// Implemented method - provides functionality that all vehicles share
13-
public string GetInfo()
14-
{
15-
return $"This is a {_brand} vehicle.";
16-
}
13+
public string GetInfo() => $"This is a {_brand} vehicle.";
1714

1815
// Another implemented method
19-
public virtual void StartEngine()
20-
{
21-
Console.WriteLine($"{_brand} engine is starting...");
22-
}
16+
public virtual void StartEngine() => Console.WriteLine($"{_brand} engine is starting...");
2317

2418
// Abstract method - must be implemented by derived classes
2519
public abstract void Move();
@@ -33,10 +27,7 @@ public class Car : Vehicle
3327
public Car(string brand) : base(brand) { }
3428

3529
// Implementation of abstract method
36-
public override void Move()
37-
{
38-
Console.WriteLine($"{_brand} car is driving on the road.");
39-
}
30+
public override void Move() => Console.WriteLine($"{_brand} car is driving on the road.");
4031

4132
// Implementation of abstract property
4233
public override int MaxSpeed => 200;
@@ -47,10 +38,7 @@ public class Boat : Vehicle
4738
public Boat(string brand) : base(brand) { }
4839

4940
// Implementation of abstract method
50-
public override void Move()
51-
{
52-
Console.WriteLine($"{_brand} boat is sailing on the water.");
53-
}
41+
public override void Move() => Console.WriteLine($"{_brand} boat is sailing on the water.");
5442

5543
// Implementation of abstract property
5644
public override int MaxSpeed => 50;

docs/csharp/language-reference/keywords/snippets/abstract/abstract.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>net8.0</TargetFramework>
5+
<TargetFramework>net9.0</TargetFramework>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
88
</PropertyGroup>

0 commit comments

Comments
 (0)