具有特殊字符的 C# 变量名

标签 c# .net c#-4.0

我想在 C# 中的 string 变量名中包含一些特殊字符。

示例: string foo-bar = String.Empty;

据我所知,我不能像在上面的例子中提到的那样声明一个变量。 有没有办法声明一个包含“-”的变量名?

最佳答案

来自 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# 变量名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25217167/

相关文章:

c# - 如何通过在类中创建的方法在表单上创建按钮?

c# - 使用 System.IO.Directory.Delete 删除目录

c# - 防止事件冒泡C#

jquery - 将绘制的图像保存在asp.net服务器的canvas中

c# - 创建 Windows 服务时 SchedularCallBack 出错

c# - 在 iTextSharp 中从 PDF 获取文档属性

c# - ASP.NET Web API Swagger(Swashbuckle)重复OperationId

c# - 'System.ServiceModel.Diagnostics.TraceUtility' 的类型初始值设定项

c# - 为什么无法序列化 DataTable。未设置数据表名称?

wpf - 如何使窗口最大化时所有控件按比例相应调整大小?