javascript
Brief description  about Online courses   join in Online courses
OR

DotNet Concepts

Agrim  Gupta
Agrim Gupta
Net Developers

First things first! Before one deep dives into the programming concepts of any language, one needs to understand the terms used commonly and grasp their meaning. To begin with, we will go thru some of the most commonly used terms.

Framework

One must have heard this term a lot many times and used them in their conversation as well. Many a times these terms are used loosely without an understanding; sometimes used in the wrong places as well.

Let us take the first step into the .NET world by looking at the definition of framework.

.NET Framework (Common referred as .NET) is Microsoft’s application development platform that enables developers to rapidly build wide variety of applications that runs on windows operating system like web applications, windows applications, console applications, web services etc.

This leads us to the next logical question – what else does a .NET framework contain?
.NET Framework consists of -
Common Language Runtime (CLR)
Base Class Library (BCL)

Now, let us understand the meaning of the above newly learnt terms in a little more detail.

Common Language Runtime

Simply put, the .NET Framework has a runtime environment, the Common Language Runtime that is responsible for executing the .NET code on the windows operating system. It abstracts (hides the complexity) code execution and provides different services like memory management, security, exception handling.

Memory Management: Major feature of CLR is that at runtime it automatically handles allocation and de-allocation of memory resources. As CLR provides automatic memory management, developer need not worry about memory management there by increases developer productivity and the code quality.

Garbage collector (GC) is responsible for collecting the unused objects. CLR invokes GC automatically and an application can also invoke GC explicitly by making use of GC.Collect method.

Code which makes use of CLR is called as managed code. Managed code takes advantage of the memory management services provided by the CLR. Code which does not make use of CLR such code written to call COM components is called as un managed code.

Base Class Library

Base Class library is a set of pre-built code for handling common programming tasks like Request processing, Rendering (output) data, file operations, database operations, XML operations, graphical operations etc.  

Now that we have learned the contents of the framework, we will look at some of the other commonly used terms and understand their meaning. These terms too will be used in conversations and our future modules. Hence it is required that you imbibe the meanings of these terms conceptually at this point in time.

Common Type System (CTS)

Common Type System is a specification that defines the data types supported by CLR so that program written in one .NET Language can make use of the program written  using another .NET Language. .NET Framework supports multiple languages and this feature is called language independence.

Just a note on the language independence - .NET programs can be written in C#, VB.NET, J# - to name a few languages. This gives the developer to pick and choose a language in which he/she is comfortable.

Intermediate Language

Code that is written in C#, VB.NET etc. are converted into Intermediate code (IL) by the respective .NET language compliers.

CLR then converts IL into machine language during the code execution.

Assemblies

Assembly is a physical unit of deployment. Assembly consists of one or more files and is used for versioning and code security. Assemblies are DLL or EXE files that gets generated when code written in .NET Language like C#, VB.NET is compiled and hence contains IL code.

At this point in time, it may be difficult to grasp the meaning of an assembly in its entirety. Assemblies will covered in detail in the coming module.

Namespaces

There are a lot of built in classes that come with the framework. These are extensively used in programming. When we make use of methods that are in these built in classes, we need to provide a reference to these classes. Classes are present in different logical groupings. A fully qualified name needs to be referenced.

Namespace is a logical grouping of .NET code. To ease application maintenance as code gets bigger, .NET provides this feature to arrange the code according to functionality.

One Assembly can contain multiple namespaces. Similarly one namespace can be included in multiple assemblies.

The table below lists some of the common namespaces contained in .Net Framework class library.

 
Now that we have covered the basics of .NET, we will deep dive into the syntax and some basic structures in C# and VB.NET. In the next two sections, we will be dealing with some basics of C# and VB.NET.

Object Oriented Programming (OOP)
Object Oriented Programming (OOP)

Object Oriented Programming is programming style and .NET Languages like C# (read as ‘C’ Sharp), VB.NET etc. makes use of OOPs concepts. Hence the study of the programming concepts and programming in .NET would not be possible without the study of OOPs

Alternative to Object Orientated programming style is Procedural programming; Procedural programming adopts a step-by-step approach to implement a particular task. C is one of the best examples for procedural language.

Some of the basic and important OOPs concepts are explained below.

Class

OOPs is based on the real word modelling. A Class is a programmatic representation of real world entity. Class contains data related to an entity and functions that operate on that data.
Definition – A class is a template or a blueprint of an entity. It describes what an entity has and how an entity behaves. A class does not have an existence. To give an example, Vehicle can be considered a Class. Animal can be a Class. In both these examples, just the term “Vehicle” or “Animal” conveys meaning or concept.  They have certain characteristics that one can visualize.

Class contains data in variables which are called as data members and its functions are called as member functions. Functions are used to implement the behavior of an entity. All classes are reference types.

In C# classes are declared by using the keyword class followed by the class name and a set of class members surrounded by curly braces.

In VB.NET classes are declared by using the keyword Class followed by the class name and a set of class members surrounded by End Class marker.

Definition – An instance of a Class is an Object. It is the Object that gives a blueprint (Class) an existence. Memory is allocated when objects are instantiated with the New keyword

To explain with our previous example,
Car is an Object, Bike is an Object, Cycle is an Object. (Car, Bike, Cycle are instances of Vehicle class )
Tiger is an Object, Lion is an Object, Elephant is an Object (Tiger, Lion, Elephant are instances of Animal class)

Object declaration examples:

 

Encapsulation

Encapsulation is an approach to implement abstraction. Abstraction means to hide complexity or unwanted details. Encapsulation helps to achieve data hiding and hence provides data security.

Data hiding: Class contains private data members which are not accessible to the users of the class. These can be modified only internally by the class. Class contains public functions through which user can interact with these data. In short, direct manipulation of data by user is avoided.
 
C# and VB.NET provide various access modifiers to define the level of access for data and functions.

 

Inheritance

In real life we can observe that children inherit certain characteristics from their parents. So inheritance allows us pass characteristics from one entity to another entity.  In programming inheritance is a way to reuse things which belongs to particular entity.

Base Class: Class which contains common properties and functions to be shared with other classes by inheritance is called base class.
Derived Class: Class which inherits the base class is called derived class ( Derived from base class)

Let us take an example of a company. Company needs to maintain information of both employees as well as customers. Employee and Customer have common characteristics or information such as Name, Address, and Telephone. But only customers will have orders and only employees are paid salary. In this scenario we can come up common class by name Person which takes care of personal information. Employee class can take care of salary information and Customer class can take of order information. Declaration of classes for this scenario is given below.

 

 

Polymorphism

The word “polymorphism” means “different forms”. In OOPs it means the ability of an entity to exhibit different forms at runtime. It allows methods and properties in multiple classes to have the same signature with different behavior.

Signature is term which is used to refer to the combination of member name, member type, parameters datatype and a return type

In the above example all three classes i.e. Person, Employee and Customer are displaying information but different information. In this scenario, all three class can implement a method with the same signature but with different functionality. Person class can print only personal information. Employee class can print salary information along with personal information. Customer class can print order information along with the personal information.

Syntax and structure for implementing the above scenario is given below. Notice the difference in keywords between C# and VB.NET.

 

 

Method Hiding: If a method in a derived class is declared with the same signature of a method in the base class but without overriding the base class method then that method is said to hide the base class method. This scenario is known as method hiding and which version of the method gets called depends on the type of the variable used to reference the instance, not the type of the instance itself. This prevents polymorphism.

In C#, this scenario is implemented by declaring the base class method and derived class method as virtual and new respectively.
In VB.NET this scenario is implemented by declaring the base class method and derived class method as Overridable and Shadows respectively.


Abstract Class and Function

Abstract class is class which contains one or more abstract functions and which can’t be instantiated. Abstract function is a function without any implementation; it will have only a declaration. Abstract function must be overridden in the derived class.

 

Interface

Definition – An Interface contains only definition or signatures of methods, but does not any implementation. While abstract class can contain methods with or without implementation, interface can only have members without implementation. Implementation will be taken care by the class which needs to implement the interface. Interface acts as standard or contract between the classes.

A class can implement multiple interfaces but can inherit only one abstract class.

The definition and usage of an interface is explained in the below example for C# and VB.NET
 

Constructors

Constructors are special member functions that are called to initialize data members. Constructors do not return any value. The different types of constructors are
•    Default constructors: These constructors are called automatically when an instance of class or object is created.
•    Parameterized constructors: These constructors are called explicitly by passing appropriate parameters.



Destructors: Destructors are special member functions used to release the memory occupied by objects. In .NET destructors are called automatically when an object is removed from the memory by the garbage collector. We can’t call destructors explicitly.

Typically we need not implement destructors as CLR takes care of memory management and removes unused resources using garbage collector. Garbage collection may happen any time after object goes out of scope. So there may be delay between the garbage collection and objects going out of scope.
In case we need to release any expensive unmanaged resources from the memory before the garbage collection, then we need to implement System.ID isposable interface.
In C# destructors are declared with a prefix of ~ to the class name.

 

Write your comment now
 
Reader's comments(21)
1: Its helps a lot !
Can you describe a article on collections ?
Posted by:nithish - 22 Feb, 2018
2: the concept is very easy to understand.......
Posted by:abi - 24 Aug, 2016
3: the concept is very understandable way
Posted by:akhi - 15 May, 2016
4: Wonderful explanation of concepts.
Thanks
Posted by:kishan - 31 Jan, 2016
5: thanx sir its's very useful to me...
Posted by:satyajeet - 08 Dec, 2015
6: thanks
Posted by:Prashant - 18 Nov, 2015
7: مقال جيد جدا وشكرا
Posted by:Ahmed - 13 Oct, 2015
8: nimista thubrean..
Posted by:dss - 18 Aug, 2015
9: Thanks to information
Posted by:barath - 16 Mar, 2015
10: aaaaaa
Posted by:aaaa - 21 Aug, 2014
11: thanks you..............
Posted by:maheshwari - 07 Aug, 2014
12: thanks....
Posted by:Libersan - 28 Jul, 2014
13: Very very very nice
Posted by:dev - 18 May, 2014
14: thanks..
Posted by:lavanya - 09 May, 2014
15: Thank you
Posted by:Devi - 03 Jan, 2014
16: tnx a lot!!!
Posted by:monika - 29 Nov, 2013
17: Nice Article with good and short description.
Posted by:Neha - 22 Sep, 2013
18: very nicely and briefely explained
Posted by:Nitin - 18 Sep, 2013
19: It was a very nice topic. This topic is explained "Why Dotnot is a Object oriented?"
Posted by:Mahadev - 30 May, 2012
20:
thanks..
narayan Replied to: Mahadev - 02 Jun, 2014
21:
Tanq sir, Its really good
amrutha Replied to: narayan - 23 Mar, 2016