內容相關性關鍵字 (C++/CLI 和 C++/CX)Context-Sensitive Keywords (C++/CLI and C++/CX)

「內容相關性關鍵字」是只能在特定內容中辨識的語言元素。Context-sensitive keywords are language elements that are recognized only in specific contexts. 在特定內容之外,內容相關性關鍵字可以是使用者定義的符號。Outside the specific context, a context-sensitive keyword can be a user-defined symbol.

所有執行階段All Runtimes

備註Remarks

下列是內容相關性關鍵字清單:The following is a list of context-sensitive keywords:

基於可讀性目的,您可能希望限制將內容相關性關鍵字當作使用者定義符號使用。For readability purposes, you may want to limit your use of context-sensitive keywords as user-defined symbols.

Windows 執行階段Windows Runtime

備註Remarks

(沒有這項功能的平台特定備註。)(There are no platform-specific remarks for this feature.)

規格需求Requirements

編譯器選項:/ZWCompiler option: /ZW

Common Language RuntimeCommon Language Runtime

備註Remarks

(沒有這項功能的平台特定備註。)(There are no platform-specific remarks for this feature.)

規格需求Requirements

編譯器選項:/clrCompiler option: /clr

範例Examples

下列程式碼範例顯示在適當的內容中, property 可以使用內容相關的關鍵字來定義屬性和變數。The following code example shows that in the appropriate context, the property context-sensitive keyword can be used to define a property and a variable.

// context_sensitive_keywords.cpp
// compile with: /clr
public ref class C {
   int MyInt;
public:
   C() : MyInt(99) {}

   property int Property_Block {   // context-sensitive keyword
      int get() { return MyInt; }
   }
};

int main() {
   int property = 0;               // variable name
   C ^ MyC = gcnew C();
   property = MyC->Property_Block;
   System::Console::WriteLine(++property);
}
100

請參閱See also

適用于 .NET 和 UWP 的元件延伸模組Component Extensions for .NET and UWP