MVC Design Pattern

What is MVC Pattern ?

MVC stands for Model-View-Controller (MVC), it is a software design pattern that decouples various concerns in an application.

  • It is a powerful and effective way of designing applications that separates the UI (User Interface) logic from the data access and data manipulation logic.
  • It’s explicit separation of concerns adds some extra complexity to an application’s design, but it provides enormous benefits to the application’s stability, functionality and testability.

Generics in C# part 2

If you haven’t gone through my previous article on generics then please go through it here.

In my previous article, we discussed about the type safety and code re-usability feature of generics, continuing on that, in this article we will discuss about the performance improvement generics brings in to our code.

How usage of generics improves performance ?

Generics can bring performance improvement in terms of speed and memory consumption as follows.

  • With generics in our program, we don’t need to use type casting, that eliminates the extra work compiler does to check the type at run-time. This certainly improves the performance of the application.
  • Another benefits generics bring is that, it eliminates the possibility of boxing and un-boxing in most of the situations, which generally improves the performance and reduces the memory consumption.


Generics in C#.Net – Introduction

Generics is a very interesting and powerful feature in C# 2.0, It provides a type safety and reusable programming framework. In this article, we will learn about the basic concept of generics, its benefits and the usage.

What is generics ? 

In simple definition, we can say that generics is a mechanism in C#, which allows to write type safe, reusable and high performance code.

In other words, generics allows us to design  classes, methods, Interface and delegates with a specific data type. The data type information is passed to the generic type during declaration and instantiation time.

This enables in developing common classes, methods, Interface and delegates, which helps in the application performance, improves the productivity and provides the type safety feature.

This is what Microsoft says about generics.

 “Generics are the most powerful feature of C# 2.0. Generics allow you to define type-safe data structures, without committing to actual data types. This results in a significant performance boost and higher quality code, because you get to reuse data processing algorithms without duplicating type-specific code”


Null Coalescing Operator in C#

This is an extension to the article on nullable types, If you haven’t gone through the article then please have a look here .

Null Coalescing Operator (??) :

This is a C# operator that is basically used to set the default value of a variable,  It takes two operands, If the left operand is null, then the right operand is returned else the left operand.

X = Y ?? Z ;


Boxing and Unboxing in C#.Net

Before going through Boxing and Unboxing concept in C#, it’s important to know about value type and reference type variables. Please go through my article here.

Boxing :

It is the process of converting a value type variable to a reference type variable (object). That means the C#.Net converts a value type variable of type (int, float, bool etc) to an object which is a  reference type variable.

In below code snippet, we have declared a value type int x and then performing a boxing operation that converts the value type   x  to an object  obj  which is a reference type.


Nullable Types in C#.Net

Nullable Types in C#.Net, Before going through in details. It is important to know Reference types and Value Types. If you haven’t gone through my previous article on Reference type and value type then ,you can go through here.

What is a nullable Type ?

Nullable types are special data type in, to which you can assign null value.

Lets say you have declared a variable as int i = 0, Now you want to assign null to it at run-time. If you write i = null then compiler throws error as shown below. Now question arises How this can be achieved ?

Nullable Type
Figure – 1 – Declaration Type Exception


Value Type and Reference Type in C#.Net

In, all data types are mainly classified in to two categories.

  • Value Type
  • Reference Type

Value Type : 

A value type holds the value itself in a stack. For example, when we declare a value type variable as   int X = 500 then the C# compiler allocates some memory space from the stack and stores the value, as shown in the image. 

Figure – 1 – Value Type

What happens when we assign one value type to another ?

If we assign a value type variable to another value type variable then the value is copied, and in that case both of the variables work independently and any change to any of the variable doesn’t affect the other.

Data Types in C#.Net

What is a data type ?

Data types or variable are an important thing in any programming language. It is the basic starting point for a programmer. It generally tells to the compiler the type of value it can hold.

In below example we have declared a string variable in as.  String s = "Hello"  .  It tells to the compiler that string is a data type that holds a text value.

In above example, we have declared a integer type in It tells to the compiler that int is a type that will be used to hold numbers.

Data types has some specific size and length. If we declare a type and at run time if the value it holds exceeds the max limit that the type can hold then we get the data overflow issues. So its very important to have proper data types in our program.
Continue reading

Welcome to The Dot-net Guide :)

IMG_0126The idea behind this blogging website came to me on a fine Saturday morning. As I was  lying down on my bed and lazily browsing Facebook, then accidentally I stumbled upon an article on blogging. The article was all about “How you can blog in 100 different ways ? “. It was quite interesting to learn how people from different interest, technology share their knowledge and experience to the larger audience.