Namespace
Namespace is a design or a way which separates the set of names from each other. If two names are same in two different namespaces, then there will be no conflict in the names of those classes as they belong to different namespaces. The syntax is:
namespace namespace_name;
Here namespace is the keyword & it is followed by namespace name.
Preprocessor Directive
The directives which instruct the compiler to process the information before the actual compilation starts are called preprocessor directives. These directives start with # & they are not statements so, they don’t end with semicolon. Different preprocessor directives are:
Preprocessor Directive | Description |
#define | It defines a sequence of characters, called symbol. |
#undef | It allows you to undefine a symbol. |
#else | It allows to create a compound conditional directive, along with #if. |
#if | It allows testing a symbol or symbols to see if they evaluate to true. |
#warning | It allows generating a level one warning from a specific location in your code. |
#elif | It allows creating a compound conditional directive. |
#endif | Specifies the end of a conditional directive. |
#line | It lets you modify the compiler's line number and (optionally) the file name output for errors and warnings. |
#region | It lets you specify a block of code that you can expand or collapse when using the outlining feature of the Visual Studio Code Editor. |
#error | It allows generating an error from a specific location in your code. |
#endregion | It marks the end of a #region block. |
Table reference.
Class
Class is a container that holds data & methods together. We define class by using keyword class followed by a class name. After class declaration it contains parenthesis inside which data & methods both are declared. Classes consist of variables, objects & methods. Its syntax is:
Object
Object is an instance of class. It does not hold the data to it but it is like a handler which specifies the class to be used. Its syntax is:
Here object obj is being created for the class Classname.
Method
Method contains a group of statements which collectively performs some task. Methods are declared inside a class and can be called from outside. It is used to perform some function. Its syntax is:
Access Specifier
Access specifier decides whether the method or the class is accessible to another class or not. It means whether the data & methods inside one class or method can be used by another class or not. These are of 5 types:
- Private: The function or class with private access specifier are accessible in the same class it is written.
- Protected: The function or class with protected access specifier are accessible in the same class it is written as well as the inherited child classes.
- Public: The function or class with public access specifier are accessible to all the classes.
- Internal: The function or class with internal access specifier are accessible in the same application it is written but not to the other namespaces. It is the default access specifier for all c# projects.
5. Protected
internal: The function or class with protected internal access specifier
are accessible in the same application of a namespace as well as the inherited
child classes inside or outside the same namespace.
Thanks for the feedback friends, i have edited the article & I hope this would be fine by now.
Your feedbacks really help me as well as my readers. Please do comment & send feedbacks.