In this c# tutorial, you will learn about how to use literals in c#, tokens in c#, types of tokens in c#.
TOKENS IN C#
- C# program is a collection of tokens, comments and whitespaces
- A token is a smallest unit in the program
TYPES OF TOKENS
1. Keywords
2. Identifiers
3. Operators
4. Punctuators
5. Literals
NOTE
- White spaces and comments are not tokens; They may act as a separator for tokens.
1. Keywords
- Keywords are reserved words
- It implements the specific features of the language
- It can’t be used as identifiers but c# allows the use of keywords as identifiers when they are prefixed with the ‘@‘ symbol
Example
int if=99; // Error (Because keyword is not allowed)
int @if=99; // correct.
2. Identifiers
- Names given to various programming elements such as variables, methods, class, array, interfaces, etc, …
3. Operators
- A special symbol is used to perform various useful tasks.
Example:
- +, -, /, *, ++, –, …etc
4. Punctuators
Examples
Statements
- Sentences in natural language
- Executable combination of tokens ending with a semicolon
Types of Statements
- Empty statements
- Loop statements (Ex. for, while, do-while)
- Labeled statements (Ex. goto label)
- Declaration statements (Ex. int num=191)
- Expression statements (Ex. c=a*b)
- Selection statements (Ex. if, if-else, nested if, switch)
5. Literals
- Constant values are assigned to variables (Literals)
BACKSLASH CHARACTER LITERALS
- C# supports some special backslash character literals
S.N | CONSTANT | MEANING |
1. | \a | Alert |
2. | \b | Back space |
3. | \f | Form feed |
4. | \n | New line |
5. | \’ | Single quote |
6. | \\” | Double quote |
7. | ‘\0’ | Null character |
General String
- Set of characters without any special symbols
Example
WriteLine(“Hello World”);
Special String
- Set of characters with special symbols
Example
WriteLine(“\n\t World”); // special characters like /n, /t
Formatted String
general string + special string + formatted syntax
Example
WriteLine(“{0}”, name); // print name using formatted syntax
More Tutorials
-
How to convert Word to Number in Bash Script
-
How to Count Word Frequency in Bash Script
-
Bash Script – How to convert Number to Words
-
Linux Commands – How to use cat, zcat, tac and lolcat commands in Linux