dotnet / dotnet/docs

Difference in car type in the same example

Open
#55,433 0 comments 0 reactions 1 assignee Claimed by @BillWagner View on GitHub
dotnet-csharp/svc fundamentals/subsvc
Dominant language
No language data
Stars
4.8k
Forks
6.1k
Avg merge
19h 10m
Merged PRs (30d)
268

Description

### Type of issue

Other (describe below)

### Description

### Description

The declaration of the variable `car2` in `TestCars1` differs between the presentation of the standalone snippet test at the beginning of the article and the final code at the end.
The snippet declare `car2` as a `Car`
```C#
Car car2 = new ConvertibleCar();
```
However in the full project listing at the end, the same `car2` is declared as a `ConvertibleCar`
```C#
ConvertibleCar car2 = new ConvertibleCar();
```
The output is the same either way, but it's confusing. It's writent that "The type of the object is ConvertibleCar" and for the other car, the `Minivan`, the declared type is that of the derived class. Since `TestCars2` already tests the case where all object have type `Car`, the final code seems more accurate.

### Suggested fix

Update the standalone snippet of `TestCars1` to match the full listing, i.e. use:
```C#
ConvertibleCar car2 = new ConvertibleCar();
```

### Page URL

https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/knowing-when-to-use-override-and-new-keywords

### Content source URL

https://github.com/dotnet/docs/blob/main/docs/csharp/programming-guide/classes-and-structs/knowing-when-to-use-override-and-new-keywords.md

### Document Version Independent Id

c88cfd2b-fdee-64eb-c26c-4d808e82e8b6

### Platform Id

b04bd07e-965d-f8c1-0ffe-fb4c35394fba

### Article author

@BillWagner

### Metadata

* ID: 4702e20f-4482-e0ce-bf61-784d436b64d5
* PlatformId: b04bd07e-965d-f8c1-0ffe-fb4c35394fba
* Service: **dotnet-csharp**
* Sub-service: **fundamentals**

[Related Issues](https://github.com/dotnet/docs/issues?q=is%3Aissue+is%3Aopen+c88cfd2b-fdee-64eb-c26c-4d808e82e8b6)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.