#224 – One Example of a Problem that Code Analysis Would Catch

As an example of the type of issues that code analysis would catch, consider the following piece of code.

        static void Main()
            Console.WriteLine("Grande schmande, just give me some coffee..");

This code obviously works fine–it just prints out a string.  But if we want to someday localize this program, we’ll want to be reading the string from a resource file, rather than hard-coding it like this.  So when we build the project with code analysis turned on, we see the following warning:

CA1303: Do not pass literals as localized parameters

An externally visible method passes a string literal as a parameter to a constructor or method in the .NET Framework class library, and that string should be localizable.

We see this warning in the Error List window when we build the project.