Click to Rate and Give Feedback
MSDN
MSDN Library
Visual Studio 2008
Visual Studio
Visual C#
C# Reference
C# Keywords

  Switch on low bandwidth view
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.

Concepts

Other Resources

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

(add and remove actually are listed above. It's under "Contextual Keywords")

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;
}
}
Descending is missing from the list of Contextual Keywords      Rick Strahl   |   Edit   |   Show History
The descending keyword (as in orderby ... descending) is not listed above.
Missing Keywords      MMayerl ... gäst   |   Edit   |   Show History
There's actually a bunch of keywords missing!

As mentioned before, there are add and remove, and, of coure, descending and (!) ascending!

In addition to this, I miss the context-based alias-Keyword (as in extern alias).

Then, if I may ask, why don't you document the __makeref, __reftype, __refvalue und __arglist keywords?

And last but not least, though they are not really "keywords", I think that attribute path specifiers would fit here (assembly, module, method etc.)


Tags What's this?: Add a tag
Flag as ContentBug
Why the length is 14 & 15?      variableF ... joelypolly   |   Edit   |   Show History

using System;

class Myclass
{
static void Main()
{
//int[] iPages = { 5,345345 };
//Console.WriteLine(iPages.ToString().Length); => This will output 14

//string[] iPages = { "5","adf","345345" };
//Console.WriteLine(iPages.ToString().Length); => This will output 15
}

}

I'm diving with C# data types, can someone please explain why the results are 14, 15 always?

Reply: If you view the iPages.ToString() you will get something like "System.String[]" Or "System.Int32[]" it doesn't actually print what is contained in the array

Tags What's this?: Add a tag
Flag as ContentBug
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker