2012-11-29

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.

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.

-

3 comments:

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

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

    ReplyDelete