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.

Let’s 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:
int j; OR int j=5;

Constants:
const int j=5;

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
{
string stuname;
int rollno;
string stram;
public stu()
{
rollno=10;
stuname=’John’;
}
}
One other popular data structure used in C# is array. It contains variables of same data types which are referred as array elements. Array can be single dimensional or multidimensional.

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,

……
public int test(int a, int b);
…….
public string test(String c,Stringd)
………

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.

SetApp - 100 Apps for everything you ever wanted to do on Mac

Add to My Yahoo!


FREE Subscription

Subscribe to our mailing list and receive new articles
through email. Keep yourself updated with latest
developments in the industry.

Name:
Email:

Note : We never rent, trade, or sell my email lists to
anyone. We assure that your privacy is respected
and protected.

Visit .NET Programming Tutorial Homepage

______________________________________________________

Recommended Resource

| About Runtime Components of .NET Framework | About Session Management in a Web Based Enterprise Application | An introduction to Microsoft Mobile Internet Toolkit (MMIT) | How to Internationalize Your .NET Application | How to Create a Document Type Definition (DTD) | How to Create a .NET Windows Service Easily | Knowing the Difference Between Application Server and Web Server | Understanding Key Advantages of .NET Type System | Understanding Some Basic Language Related Features of C# |


“Amazon and the Amazon logo are trademarks of Amazon.com, Inc. or its affiliates.”

| Privacy Policy for www.dotnet-guide.com | Disclosure | Contact |

Copyright - © 2004 - 2019 - All Rights Reserved.