Team LiB
Previous Section Next Section

Appendix E: C# Keywords

As you learned earlier in this book, there are certain reserved words called keywords that have special meaning in the C# language. They are used to declare accessibility, control execution flow, define types, and so forth.

For reference purposes, we present in Table E-1 a complete list of the C# keywords, along with a brief description of how each is used and a pointer to that chapter in which we discussed the keyword in depth. Those keywords with an asterisk in the Chapter column are beyond the scope of this book to address in depth, but have been included here in the interest of completeness.

Table E-1: C# Keywords

Keyword

Introduced in Chapter

Description

abstract

7

Indicates a class that can be extended but can't be instantiated or a method that must be implemented.

as

*

A casting operator that returns null if the cast fails.

base

13

Used to access members of a base class hidden by similarly named members in a derived class or struct

bool

1

A simple type that represents a Boolean value.

break

1

A jump statement used to exit from a loop or switch statement.

byte

1

A simple type that represents an 8-bit unsigned integer.

case

1

Specifies a label in a switch statement. If the constant specified in the label matches the value of the switch expression, the statements associated with the label are executed.

catch

13

Defines a block of code that is executed if a specified type of exception is thrown. Also see try and finally.

char

1

A simple type that represents a single 16-bit Unicode character.

checked

*

Both an operator and statement. Ensures that the compiler and runtime check for overflow in integer-type operations and conversions.

class

1

Designates a declaration as one for a class type.

const

13

Indicates that the value of a variable can be computed at compile time, i.e., once assigned, it can't be changed.

continue

1

A jump statement used to return to the top of a loop.

decimal

1

A simple type that represents a 128-bit high-precision decimal value.

default

1

Specifies statements to be executed if none of the preceding case clauses match the expression in a switch statement.

delegate

16

Designates a declaration as one for a delegate type. Delegates encapsulate methods as callable entities that can all be invoked with one invocation of a delegate instance.

do

1

A conditional statement that executes at least once whether or not its condition is satisfied.

double

1

A simple type that represents a 64-bit double-precision floating point value.

else

1

Part of an if conditional statement. The statement following else is executed if the condition isn't true.

enum

*

A value type representing a collection of named constants.

event

16

A member that enables a class or object to provide notifications. It must be of delegate type.

explicit

*

An operator that defines a user-defined cast conversion operator. Generally this will convert a built-in type to a user-defined type or vice versa. Explicit conversion operators must be invoked with a cast.

extern

*

Indicates that a method will be implemented externally, typically in a language other than C#.

false

1

A Boolean literal.

finally

13

Defines a block of code that is always executed when the program control leaves a try block. See also the try and catch keywords.

fixed

*

Assigns a pointer to a variable at a fixed memory location while a block of code executes.

float

1

A simple type that represents a 32-bit single-precision floating point value.

for

1

Defines a loop statement that executes as long as a specified condition holds.

foreach

13

Used to iterate through the elements of a collection.

goto

*

A jump statement that redirects program execution to a labeled statement.

if

1

A conditional statement that selects a statement for execution based on the value of a Boolean expression.

implicit

*

An operator that defines a user-defined cast conversion operator. Generally this will convert a predefined type to a user-defined type or vice versa. Implicit conversion operators must be invoked with a cast.

in

13

Part of the iteration syntax in a foreach statement. The in keyword is placed between the variable name and the collection to be iterated over.

int

1

A simple type that represents a 32-bit signed integer value.

interface

7

Designates a declaration as one for an interface type, i.e., a contract that an implementing class or struct must adhere to.

internal

13

An access modifier. A code element with internal access is available to other types in the same assembly. An assembly can be a DLL or EXE file.

is

13

A comparison operator that compares the types of two objects.

lock

*

Used in multithreaded programming to place a mutual exclusion lock (mutex) around a variable.

long

1

A simple type that represents a 64-bit signed integer value.

namespace

1

Defines a logical grouping of types and namespaces.

new

1

An operator used to call a constructor. Also, a modifier used to hide rather than override an inherited method with the same signature.

null

1

A literal that represents the "zero equivalent" value for a reference type.

object

13

A predefined reference type that represents the ultimate base class for all other reference types. It's an alias for the predefined System.Object type.

operator

*

Used when declaring or overloading an operator.

out

*

Indicates that a parameter will affect the value of its argument, but that the argument doesn't have to be initialized before being passed in to the method.

override

5

A modifier indicating that a method or operator will override a virtual or abstract method or an operator of the same name defined in a base class.

params

*

Declares a parameter array. If used, it must modify the last parameter specified. Enables optional parameters.

private

1

An access modifier. A member with private access is only available inside the type in which the member is defined.

protected

13

An access modifier. A member with protected access is available to the type in which the member is defined, and to types derived from that type.

public

1

An access modifier. A member with public access is freely available inside or outside of the class or namespace in which the member is defined.

readonly

13

Indicates that the value of a variable can't be changed once it has been initialized.

ref

*

Indicates that a parameter may affect the value of its argument.

return

1

A jump statement used to exit a method. The execution returns to the caller of the method.

sbyte

*

A simple type that represents an 8-bit signed integer.

sealed

13

Prevents types from being derived from and methods and properties from being overridden.

short

1

A simple type that represents a 16-bit signed integer value.

sizeof

*

An operator that returns the size of a value type in bytes.

stackalloc

*

Returns a pointer to a block of memory allocated on the stack.

static

7

A static member is associated with the type in which it's declared rather than with an instance of the type.

string

13

A predefined reference type that represents Unicode character strings. It's an alias for the predefined System.String type.

struct

*

A struct is a value type that can declare constants, fields, methods, properties, indexers, operators, constructors, and nested types.

switch

1

A selection statement that executes a statement list associated with a label that matches the value of an expression.

this

13

References the current instance of a type.

throw

*

Causes an exception to be thrown.

true

1

A Boolean literal.

try

13

Part of an exception-handling block of code. The try block contains code that might throw an exception. See also the catch and finally keywords.

typeof

13

An operator that returns the type of the argument passed to it.

uint

*

A simple type that represents a 32-bit unsigned integer value.

ulong

*

A simple type that represents a 64-bit unsigned integer value.

unchecked

*

Suppresses overflow checking.

unsafe

*

Marks a block of code, method, or class that contains pointer operations.

ushort

*

A simple type that represents a 16-bit unsigned integer value.

using

1

When applied to a namespace, the using keyword allows access to the types in a namespace without having to specify the fully qualified type names. Also used for defining finalization scope.

virtual

5

A method modifier indicating that the method can be overridden.

void

1

The return type for methods that don't return a value.

volatile

*

Indicates that an attribute can be modified by the operating system, some type of hardware device, or a concurrently executing thread.

while

1

A while conditional statement executes a statement zero or more times based on a condition. The while part of a do statement specifies the loop termination condition.


Team LiB
Previous Section Next Section