Need help in Generic class
Hi all,
Could somebody pls teach me what is generic class and how to use it in .net application????
Thanks,
Sumit
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Naveen KumarPosted Sep 2, 2009, 5:48 AM
from generics we can acheive the typesafety.for example
Normal list: list.add(1);list.add("adfasdf"); this is valid but invalid in runtime. we are losing the type safety.
generics list: list
this is one more advantage with generics.
Roei BarPosted Sep 2, 2009, 5:22 AM
the idea is to have a nontyped return value, just like object only it is actually a type, and could could actually be a multiType
lets say you have multiple products type
1. Fridge
2. Cars
you will create an abstract class called product that has all the bussiness modal like: weigth, Height,cost and so on
and create class Fridge : Product and class Cars : Product
then when you will say :
List
you will be able to call the List
here is a nice tutorial
http://www.artima.com/intv/genericsP.html
happy coding