What are tokens in C#?



Token is the smallest element of a program. Let us learn about identifiers and keywords in C# that are tokens −

Keywords

Keywords are reserved words predefined to the C# compiler. These keywords cannot be used as identifiers. However, if you want to use these keywords as identifiers, you may prefix the keyword with the @ character.

The following are some of the reserved keywords in C# −

abstract As Base bool Break byte case
catch char checked class Const continue decimal
default delegate Do double Else enum event
explicit extern False finally Fixed float for
foreach goto If implicit In in (generic modifier) int
interface internal Is lock Long namespace new
null object operator out out (generic modifier) override params

Identifiers

An identifier is a name used to identify a class, variable, function, or any other user-defined item. The basic rules for naming classes in C# are as follows −

  • A name must begin with a letter that could be followed by a sequence of letters, digits (0 - 9) or underscore. The first character in an identifier cannot be a digit.

  • It must not contain any embedded space or symbol such as? - + ! @ # % ^ & * ( ) [ ] { } . ; : " ' / and \. However, an underscore ( _ ) can be used.

Updated on: 2020-06-21T12:17:27+05:30

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements