在C#源代码中使用特殊字符(例如“ñ")是错误的吗? [英] Is it wrong to use special characters in C# source code, such as "ñ"?

查看:141
本文介绍了在C#源代码中使用特殊字符(例如“ñ")是错误的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,使用C#,我刚刚使用拉丁字符ñ声明了一个方法参数,然后尝试构建(编译)我的整个解决方案,并且该方法有效,因此我能够执行我的程序.但是我很想知道在用C#编写的源代码中使用特殊字符(例如拉丁字符)是否不正确?如果不正确,为什么?

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?

除了用英语编写代码更易懂和通用之外,还有其他原因在C#源代码中不使用特殊字符吗?

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.

根据规范合法可以在C#标识符,字符串等中使用非罗马字母吗?

Is it legal according to the specification to use non-Roman letters in C# identifiers, strings, and so on?

是的,绝对如此. Unicode规范分类为字母的任何字符都是合法的.有关详细信息,请参见规格.

Yes, absolutely. Any character that the Unicode specification classifies as a letter is legal. See the specification for the exact details.

在C#程序中是否存在有关非罗马字母的技术问题?

Are there any technical issues regarding non-Roman letters in C# programs?

是的,有几个.您可能已经知道,您既可以静态"也可以动态"将代码链接到应用程序中,而编译器就是一个应用程序.过去,我们遇到过这样的问题:编译器具有静态链接的Unicode分类算法的旧版本,而编辑器具有动态链接的当前版本,而现在,编辑器和编译器可以就什么问题达成共识.是一封合法信件,可能会引起用户混乱.但是,您提到的带重音符号的拉丁字符已经存在于Unicode标准中,以至于它们不太可能引起任何类型的问题.

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.

此外,许多人仍在使用老式的编辑器.我在1980年代后期就学会了如何在WATCOM进行编程,但我仍然经常使用WATCOM VI作为编辑器.有时我可以比在Visual Studio中更快地编写代码,因为经过23年的实践,我的手指真的很擅长. (尽管这些天我几乎都使用Visual Studio.)显然,使用1980年代编写的编辑器会遇到Unicode问题.

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.

在C#程序中是否存在有关非罗马字母的非技术性问题?

Are there any non-technical issues regarding non-Roman letters in C# programs?

很明显,是的.我个人更愿意将希腊字母用作通用类型参数,例如:

Obviously, yes. I personally would rather use Greek letters for generic type parameters, for instance:

class List<τ> : IEnumerable<τ>

或在实现数学代码时:

degrees = 180.0 * radians / π;

但是我拒绝尊重我的同事的冲动,他们不希望只是为了编辑代码而剪切和粘贴或学习奥秘的按键组合.

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.

这篇关于在C#源代码中使用特殊字符(例如“ñ")是错误的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆