Pages

Friday, 12 July 2013

What is Generics ?Generics is the Concept of defining a common Template for all kind of data type. It ensure the Type Safety.Same class or same Algorithm can be derived for all kind of Data Types . generally it is defined by "T" character.Feature and Advancement of Generics are , 1. It increases the Performance of a application.2. Reusable code.

Let's we see the Generics concepts implemented in Linked ListLinkedList is a data structure used to store the data in linear manner. LinkedList Node stores the data internally, Node consists of additional information which will have the address of next item which is added to the linked list.Data's are iterate from head to the tail using the address of next item ,which is present in the current nodeHere a,b,c,d,e,f are the data's .a is stored in address 1000, Point the next data by there address 2000b is stored in address 2000, Point the next data by there address3000c is stored in address 3000, Point the next data by there address4000d is stored in address 4000, Point the next data by there address5000e is stored in address 5000, Point the next data by there address 6000f is stored in address 6000, Point the next data by there address7000So Let we create a Common LinkedListNode class which will support all data type.Now we create a custom Linked list with one method "Add" and iterate the data through foreach class Program
{

We see the implementation of Generics in LinkedListNode . Node consists of Value which will store the data and Prev , Next store the address of Previous and Next Value.publicclass LinkedListNode<T>
{private T _value;public T Value
{get {return _value;}
}

Now the LinkedList will store the LinkedListNode on addition of each value.This class is implemented simply actually it can be implemented by adding more methods and properties. like Remove,Exists,Length etc.