C# Keywords
C# contains reserved words that have special meaning for the compiler these reserved words are called "keywords" keywords can't be used as identifier (name of variable, class, interface etc) there are 11 types of keywords.
1. Modifier Keywords2. Access Modifier Keywords
3. Statement Keywords
4. Method Parameter Keywords
5. Namespace Keywords
6. Operator Keywords
7. Access Keywords
8. Literal Keywords
9. Type Keywords
10. Contextual Keywords
11. Query Keywords
1. Modifier Keywords: are the specific keywords that indicates which can modify types and type members.
Example - Abstract, async, const, event, extern, new, override, partial, read-only, sealed, static, unsafe, virtual and volatile.
2. Access Modifier Keywords: are applied to the declaration of the class, methods, properties, fields and other member. they define the accessibility of the class and its members.
there are basic four type of Access Modifier keyword.
1. Public - The public modifier allows any part of the program in the same assembly or another assembly to access the type and its members.
2. Private - The private modifier restricts other part of the program accessing the type and its members. only same class/structs can access it.
3. Internal - The Internal modifier allows other program code in the same assembly to access the type or its members.
-> This is the default access modifier.
-> In one word "Access is limited to the current assembly".
4. Protected - The protected modifier allows code in the same class or a class that derives from that class to access the type or its members.
-> In one word "Access is limited to the containing class or derived class"
3. Statement Keyword: Statement keywords are related to program flow
Example - If, else, switch, case, do, for, foreach, in, while, break, continue, default, go to, return, yield, throw, try, catch, finally, checked, unchecked, fixed, lock.
4. Method Parameter Keywords: These keywords are applied to the parameters of a method.
Example - params, ref, out.
5. Namespace keywords - These keywords are applied with namespace and related operators.
Example - using, (.) operator, (::) operator, external alias.
-> Namespace keyword is used to declare a scope that contains a set of related objects.
6. Operator Keywords - perform miscellaneous actions
Example - as, await, is, new, sizeof, typeof, stackalloc, checked, unchecked.
7. Access Keywords - are used to access the containing class or the base class of an object or class.
Example - base, this.
8. Literal Keywords- apply to the current instance or value of an object.
Example - bull, false, true, value, void.
9. Type Keywords- are used for data types.
Example- bool, byte, char, class, decimal, double, enum, float, int, long, sbyte, short, string, struct, uint, ulong, ushort.
10. Contextual Keywords- are considered as keywords, only if used in specific contexts. they are not reserved and so can used as names or identifiers.
Example - add, var, dynamic, global, set, value.
public static int this {get; set;} <-- a="" b="" is="" this="">reserved keyword--> here
public static int var {get; set;} <-- a="" b="" is="" var="">contextual keyword--> here.
11. Query Keyword - are contextual keywords used in LINQ Queries
Example - from, where, select, group, into, order by, join, let, in, on, equals, by, ascending, descending.
Comments
Post a Comment