Working with Variables, Operators, and Expressions in Microsoft Visual C#

  • 11/18/2015

Using identifiers

Identifiers are the names that you use to identify the elements in your programs, such as namespaces, classes, methods, and variables. (You will learn about variables shortly.) In C#, you must adhere to the following syntax rules when choosing identifiers:

  • You can use only letters (uppercase and lowercase), digits, and underscore characters.
  • An identifier must start with a letter or an underscore.

For example, result, _score, footballTeam, and plan9 are all valid identifiers, whereas result%, footballTeam$, and 9plan are not.

Identifying keywords

The C# language reserves 77 identifiers for its own use, and you cannot reuse these identifiers for your own purposes. These identifiers are called keywords, and each has a particular meaning. Examples of keywords are class, namespace, and using. You’ll learn the meaning of most of the C# keywords as you proceed through this book. The following is the list of keywords:

abstract

do

in

protected

true

as

double

int

public

try

base

else

interface

readonly

typeof

bool

enum

internal

ref

uint

break

event

is

return

ulong

byte

explicit

lock

sbyte

unchecked

case

extern

long

sealed

unsafe

catch

false

namespace

short

ushort

char

finally

new

sizeof

using

checked

fixed

null

stackalloc

virtual

class

float

object

static

void

const

for

operator

string

volatile

continue

foreach

out

struct

while

decimal

goto

override

switch

default

if

params

this

delegate

implicit

private

throw

C# also uses the following identifiers. These identifiers are not reserved by C#, which means that you can use these names as identifiers for your own methods, variables, and classes, but you should avoid doing so if at all possible.

add

get

remove

alias

global

select

ascending

group

set

async

into

value

await

join

var

descending

let

where

dynamic

orderby

yield

from

partial