Understanding Some Basic Language Related Features of C#Here we will discuss the basic features of C# with two things on focus: object oriented principles and syntax of language. C# derives many of its features, expressions and operators from C++ and Java. It is totally object oriented and ignores the complex features of multiple inheritance, templates etc. Lets
start with the concept of variables and constants. We know that a specific
memory location which is named as per the language syntax rules is termed
as a variable and as the name indicates its value can change during the
execution of program.
We can refer to that location by using the actual memory address too but it is more understandable and easier to use a variable name for referring to that memory space. Similarly we have constants which also refer to a memory space whose value cannot be changed during the execution of program. They have a specific value which is specified while declaring the constants. The declaration of variables and constants in C# is as following: Variables:
Constants: Variables can be of simple types like int, double, char and memory space is allocated to them in the form of stack. They can be of object type where memory is allocated in the heap and finally we have class type variables which are user defined. Both class type and object type variables are reference type. Other custom defined data types are structures. They can have variables, methods like classes and their members can be of different data types. Consider the following example which declares a class type variable named student: class student Control statements are also important feature of any language. C# supports two conditional statements, if-else and switch. Also while, for, do-while are the looping statements supported by C#. Now we will discuss polymorphism, an object oriented phenomena supported by C#. Polymorphism can be of two types: compile time and runtime. In polymorphism, we can create methods with the same name and properties but their parameters should be different. For example it is okay to declare two methods like,
Here the name of method is same but the parameters are different. This is also called method overloading. In run time polymorphism we can call the methods of derived class using the reference of base class at the runtime.
|