c#跟c语言标识符的区别_什么是C,C ++和C#中的标识符?

c#跟c语言标识符的区别

In C, C++, C# and other programming languages, an identifier is a name that is assigned by the user for a program element such as variable, type, template, class, function or namespace. It is usually limited to letters, digits, and underscores. Certain words, such as "new," "int" and "break," are reserved keywords and cannot be used as identifiers. Identifiers are used to identify a program element in the code. 

在C,C ++, C#和其他编程语言中,标识符是用户为程序元素(例如, 变量 ,类型,模板,类,函数或名称空间)分配的名称。 它通常限于字母,数字和下划线。 某些单词(例如“ new”,“ int”和“ break”)是保留关键字,不能用作标识符。 标识符用于识别代码中的程序元素。

Computer languages have restrictions for which characters can appear in an identifier. For example, in early versions of the C and C++ languages, identifiers were restricted to a sequence of one or more ASCII letters, digits, which may not appear as the first character, and underscores. Later versions of these languages support almost all Unicode characters in an identifier with the exception of white space characters and language operators.

计算机语言对标识符中可以出现的字符有限制。 例如,在C和C ++语言的早期版本中,标识符被限制为一个或多个ASCII字母,数字(可能不会显示为第一个字符)和下划线的序列。 这些语言的更高版本支持标识符中的几乎所有Unicode字符,但空格字符和语言运算符除外。

You designate an identifier by declaring it early in the code. Then, you can use that identifier later in the program to refer to the value you assigned to the identifier.

您可以通过在代码的早期进行声明来指定标识符。 然后,您可以稍后在程序中使用该标识符来引用您分配给该标识符的值。

标识符规则 ( Rules for Identifiers )

When naming an identifier, follow these established rules:

命名标识符时,请遵循以下已建立的规则:

  • An identifier cannot be a C# keyword. Keywords have predefined special meanings to the compiler.

    标识符不能是C#关键字。 关键字对编译器具有预定义的特殊含义。
  • It cannot have two consecutive underscores.

    它不能有两个连续的下划线。
  • It can be a combination of numbers, letters, connectors, and Unicode characters.

    它可以是数字,字母,连接符和Unicode字符的组合。
  • It must start with a letter of the alphabet or an underscore, not a number.

    它必须以字母或下划线开头,而不是数字。
  • It should not include white space.

    它不应包含空格。
  • It cannot have more than 511 characters.

    它不能超过511个字符。
  • It has to be declared before it is referred.

    必须先声明它,然后再引用它。
  • Two identifiers cannot have the same name.

    两个标识符不能具有相同的名称。
  • Identifiers are case sensitive.

    标识符区分大小写。

For implementations of programming languages that are compiled, identifiers are often only compile-time entities. That is, at run time the compiled program contains references to memory addresses and offsets rather than the textual identifier tokens—these memory addresses or offsets having been assigned by the compiler to each identifier.

对于已编译的编程语言的实现,标识符通常仅是编译时实体。 也就是说,在运行时,编译后的程序包含对内存地址和偏移量的引用,而不是文本标识符标记-这些内存地址或偏移量已由编译器分配给每个标识符。

逐字标识符 ( Verbatim Identifiers )

Adding the prefix "@" to a keyword enables the keyword, which is normally reserved, to be used as an identifier, which can be useful when interfacing with other programming languages. The @ is not considered part of the identifier, so it might not be recognized in some languages. It is a special indicator to not treat what comes after it as a keyword, but rather as an identifier. This type of identifier is called a verbatim identifier. Using verbatim identifiers is allowed but strongly discouraged as a matter of style.

在关键字上添加前缀“ @”可以使通常保留的关键字用作标识符,这在与其他编程语言连接时很有用。 @不被视为标识符的一部分,因此在某些语言中可能无法识别。 这是一个特殊的指标,不要将其后的内容视为关键字,而应视为标识符。 这种类型的标识符称为逐字标识符。 允许使用逐字标识符,但出于风格考虑,强烈建议不要使用逐字标识符。

翻译自: https://www.thoughtco.com/definition-of-identifier-958092

c#跟c语言标识符的区别

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值