Xpode.com        Click here to Print this article.

What are Generics

We can have an Array List with Integers and a String in it. The technical term for this is "bad." The ArrayList is not type-safe. Type safety enlists the compiler in finding your bugs.

 

Stack <int> st = newStack<int>();

      st.Push(1);

      st.Push(2);

int i = st.Pop();

 

OR

 

class Test<T>

{   

    public T F1(T i)

    {       

        return i;

    }

}

 

Test <int> ob1 = newTest<int>();

      Response.Write(ob1.F1(20));

      Test<string> ob2 = newTest<string>();

Response.Write(ob2.F1("Amit"));

 






Contributed by:
Guest
Guest user is that user who have done some activity on website without login. Activity contains commenting on any article, uploading an image on website etc.

Resourse address on xpode.com
http://www.xpode.com/Print.aspx?Articleid=194

Click here to go on website