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
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Roei BarRank #1,271 · 1.4K reputationPosted Sep 2, 2009, 1:22 AM EDT
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
Naveen Kumar6 reputationPosted Sep 2, 2009, 1:48 AM EDT
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.