如何在C#中存取以关键字作为名字的元素
2004-09-30 16:07
381 查看
Access a Program Element That Has the Same Name as a Keyword
Problem
You need to access a member of a type, but the type or member name is the same as a C# keyword.Solution
Prefix all instances of the identifier name in your code with the at sign (@).Discussion
The .Net Framework allows you to use software components developed in other .NET languages from within your C# applications. Each language has its own set of keywords (or reserved words) and imposes different restrictions on the names that programmers can assign to program elements such as types, members, and variables. Therefore, it's possible that a programmer developing a component in another language will inadvertently use a C# keyword as the name of a program element. The symbol @ enables you to use a C# keyword as an identifier and overcome these possible naming conflicts. This code fragment instantiates an object of type operator[/i] (perhaps a telephone operator) and sets its volatile[/i] property to true—[/i]both operator[/i] and volatile[/i] are C# key words.// Instantiate an operator object @operator Operator1 = new @operator(); // Set the operator's volatile property Operator1.@volatile = true;
相关文章推荐
- 如何获得数据库里所有表的名字(SQL+C#)
- C#.NET常见问题(FAQ)-如何把函数名作为参数传递给另一个函数
- 编写高质量代码改善C#程序的157个建议——建议128:考虑让派生类的名字以基类名字作为后缀
- C#程序中:如何删除xml文件中的节点、元素
- C#中如何让某部分代码作为整体折叠和展开
- 如何让一个变量的值,作为另一个变量的名字
- 如何获得数据库里所有表的名字(SQL+C#)
- [C# 开发技巧]如何使不符合要求的元素等于离它最近的一个元素
- 在C#中如何用arcII码为0x01作为分隔符
- 如何获得数据库里所有表的名字(SQL+C#)
- 如何根据event.target得到标签元素的名字
- jasperReport如何获取jasper表格中title中的名字作为下载文件的名字
- [C#.NET] 如何 使用 多執行緒 Thread / 跨執行緒 存取UI
- 如何根据event.target得到标签元素的名字
- C#如何在webBrowser1控件通过TagName,Name查找元素(没有ID时)遍历窗体元素
- C#如何用换行符,Tab 作为split的分割符?
- C#调用外部exe作为子窗体或UI? VC++如何实现呢呢?...札记plus
- 如何获得数据库里所有表的名字(SQL+C#)
- [C#.NET] 如何 使用 BackgroundWorker 多執行緒 / 跨執行緒 存取UI
- 如何根据event.target得到标签元素的名字