具有特殊字符的C#变量名称 [英] C# variable names with special character
问题描述
我想在C#的字符串
变量名称中包含一些特殊字符。
I want to include some special characters in a string
variable name in C#.
示例:
字符串foo-bar = String.Empty;
Example: string foo-bar = String.Empty;
据我所知,我无法声明变量,如上面的例子。
是否有办法声明包含-的变量名?
As far as my understand I can't declare a variable as I mentioned in the above example. Is there any way around to declare a variable name with "-" included?
推荐答案
从 MSDN :
您不能只选择任何字符序列作为变量名。不过,这并不像听起来那样令人担心,因为您仍然可以使用非常灵活的
命名系统。
变量的基本命名规则如下:
You can't just choose any sequence of characters as a variable name. This isn't as worrying as it might sound, however, because you're still left with a very flexible naming system. The basic variable naming rules are as follows:
变量名的第一个字符必须是字母,下划线字符(_)或在符号(@)处。
随后的字符可以是字母,下划线字符或数字。
The first character of a variable name must be either a letter, an underscore character (_), or the at symbol (@). Subsequent characters may be letters, underscore characters, or numbers.
这篇关于具有特殊字符的C#变量名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!