C# Blooper №6: No warnings about unused parameters

Before reading any further, please read the disclaimer.

One common mistake that programmers make is to forget to make use of a parameter to a method. This can lead to quite subtle bugs that are hard to track down and correct.

Now, other language compilers are kind enough to warn the programmer that a parameter is unused, and they also allow temporary suppression of the warning for the rare case when such lack of use is legitimate. But not so in Visual C#. If you forget to use a parameter in Visual C#, you will not know unless you run the “Code Analysis” tool on it.

1
2
3
4
5
6
7
8
9
namespace Test6
{
    class Test
    {
        void moo( int a ) //no warning about unused parameter 'a'.
        {
        }
    }
}

For more information see Why the Microsoft C# compiler lacks many useful warnings.

Old comments

  • michael.gr 2013-03-25 15:37:52 UTC

    This blooper is about unused parameters. Yes, I would like a warning every single time a parameter goes unused.

  • Vigilanti 2013-03-25 03:12:35 UTC

    do you want it to warn you, every time you write a unused function…

    • Anonymous 2014-02-17 11:30:59 UTC

      O F C O U R S E !!!!!