Recently, using C#, I just declared a method parameters using the Latin character ñ, and I tried to build (compile) my entire solution and it works, therefore I was able to execute my program. But I’m curious to know if it is wrong to use special characters such as Latin characters in a source code written in C#? If it is wrong, why?
Besides it is more legible and universal to write code in English, are there any other reason to not use special characters in a C# source code?
Let me break this down into several questions.
Yes, absolutely. Any character that the Unicode specification classifies as a letter is legal. See the specification for the exact details.
Yes, there are a few. As you are probably aware, you can both “statically” and “dynamically” link code into an application, and the compiler is an application. We’ve had problems in the past where the compiler had a statically-linked-in old version of the Unicode classification algorithm, and the editor had a dyamically-linked-in current version, and now the editor and the compiler can disagree on what is a legal letter, which can cause user confusion. However, the accented Latin characters you mention have been in the Unicode standard so long that they are unlikely to cause any sort of problem.
Moreover, a lot of people still use old-fashioned editors; I learned how to program at WATCOM back in the late 1980’s and I still frequently use WATCOM VI as my editor. I can sometimes code faster in it than I can in Visual Studio because my fingers are just really good at it after 23 years of practice. (Though these days I use Visual Studio for almost everything.) Obviously an editor written in the 1980’s is going to have a problem with Unicode.
Obviously, yes. I personally would rather use Greek letters for generic type parameters, for instance:
or when implementing mathematical code:
But I resist the urge in deference to my coworkers who do not particularly want to be cutting and pasting, or learning arcane key combinations, just to edit my code.