Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

Contextual Keywords (C# Reference)

A contextual keyword is used to provide a specific meaning in the code, but it is not a reserved word in C#. The following contextual keywords are introduced in this section:

Keyword

Description

add

Defines a custom event accessor that is invoked when client code subscribes to the event.

get

Defines an accessor method for a property or an indexer.

global

Specifies the default global namespace, which is otherwise unnamed.

partial

Defines partial classes, structs, and interfaces throughout the same compilation unit.

remove

Defines a custom event accessor that is invoked when client code unsubscribes from the event.

set

Defines an accessor method for a property or an indexer.

value

Used to set accessors and to add or remove event handlers.

var

Enables the type of a variable declared at method scope to be determined by the compiler.

where

Adds constraints to a generic declaration. (See also where).

yield

Used in an iterator block to return a value to the enumerator object or to signal the end of iteration.

All query keywords introduced in C# 3.0 are also contextual. For more information, see Query Keywords (C# Reference).

Community Additions

ADD
Show:
© 2015 Microsoft