Warning about unused foreach variable #70643
-
This code produces only message in Visual Studio: foreach (var x in args)
{
} How can I ask compiler to generate a warning ? |
Beta Was this translation helpful? Give feedback.
Answered by
RikkiGibson
Oct 31, 2023
Replies: 1 comment 3 replies
-
You're assigning the enumerated elements to that variable, but then not using the variable. The analyzer is telling you that that's very strange and likely indicates a code bug. |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think the diagnostic in the original post is a code style diagnostic. Please see https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/overview?tabs=net-7#enable-on-build.