- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What are reserved keywords in C#?
Keywords are reserved words predefined to the C# compiler. These keywords cannot be used as identifiers. If you want to use these keywords as identifiers, you may prefix the keyword with the @ character.
In C#, some identifiers have special meaning in the context of code, such as get and set are called contextual keywords.
The following table lists the reserved keywords −
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 |
private | protected | public | readonly | ref | return | sbyte |
sealed | Short | sizeof | stackalloc | static | string | struct |
switch | This | throw | true | try | typeof | uint |
ulong | unchecked | unsafe | ushort | using | virtual | void |
volatile | While |
Let us see an example of using bool reserved keyword in C# −
Example
using System; using System.Collections; class Demo { static void Main() { bool[] arr = new bool[5]; arr[0] = true; arr[1] = true; arr[2] = false; arr[3] = false; BitArray bArr = new BitArray(arr); foreach (bool b in bArr) { Console.WriteLine(b); } bool str = arr[1]; Console.WriteLine("Value of 2nd element:"+str); } }
Output
True True False False False Value of 2nd element:True
Advertisements