dotnet / dotnet/docs

Suggest generic link to show how to suppress compiler warnings

Open
#33,722 1 comment 0 reactions 0 assignees View on GitHub
dotnet-csharp/svc errors-warnings/subsvc
Dominant language
No language data
Stars
4.8k
Forks
6.1k
Avg merge
19h 10m
Merged PRs (30d)
268

Description

The article briefly discusses the CS0184 warning. An improvement would be to add a generic link (to a separate page) at the bottom for how the warning can be disabled. This would probably need to be generic across all (level 1?) compiler warnings so you don't have to update hundreds of individual help pages.

Code snippet to generate the warning in a C# file, along with the `#pragma` to (temporarily) disable the warning.

#pragma warning disable CS0184
// Or "#pragma warning disable CS0184, CS0219" to disable multiple warnings

// Following would have generated the warning "The given expression is never of the provided ('int') type"
byte myByte = 5;
if (myByte is int)
DoSomethingElse();
else
DoSomething();

#pragma warning restore CS0184
// Or "#pragma warning restore CS0184, CS0219" to restore multiple warnings

---
#### Document Details

⚠ *Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.*

* ID: 8d019b89-8a06-a863-01d6-9530cf0799d3
* Version Independent ID: 1df16f14-1a7d-1aec-1798-2c4d5f6a2704
* Content: [Compiler Warning (level 1) CS0184](https://learn.microsoft.com/en-us/dotnet/csharp/misc/cs0184)
* Content Source: [docs/csharp/misc/cs0184.md](https://github.com/dotnet/docs/blob/main/docs/csharp/misc/cs0184.md)
* Product: **dotnet-csharp**
* Technology: **csharp-diagnostics**
* GitHub Login: @BillWagner
* Microsoft Alias: **wiwagn**

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.