Click to Rate and Give Feedback
MSDN
MSDN Library
Visual Studio 2008
Visual Studio
Visual C#
C# Reference
C# Keywords
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
C# Language Reference
C# Keywords

Keywords are predefined, reserved identifiers that have special meanings to the compiler. They cannot be used as identifiers in your program unless they include @ as a prefix. For example, @if is a valid identifier but if is not because if is a keyword.

The first table in this topic lists keywords that are reserved identifiers in any part of a C# program. The second table in this topic lists the contextual keywords in C#. Contextual keywords have special meaning only in a limited program context and can be used as identifiers outside that context. Generally, as new keywords are added to the C# language, they are added as contextual keywords in order to avoid breaking programs written in earlier versions.

A contextual keyword is used to provide a specific meaning in the code, but it is not a reserved word in C#. Some contextual keywords, such as partial and where, have special meanings in two or more contexts.

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content      
Event Delegates Add and Remove Accessor Methods      Frisky   |   Edit   |  

The add and remove accessor methods (similar to the get and set for a property) are not included in the list above.

These allow you to intercept the calls when others wire up to your events in much the same was as get/set allows you to intercept calls to a property.

Below is some sample code that shows the accessor functions.

public event EventHandler OnClick
{
add {
Debug.WriteLine("add called");
Click += value;
}
remove {
Debug.WriteLine("remove called");
Click -= value;
}
}
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker