What is Generic? explain clearly?

Answer Posted / mithun

By using a generic class, we can create classes that is type safe at compile time.

ArrayList is a highly convenient collection class that can be used without modification to store any reference or value type. Any reference or value type that is added to an ArrayList is implicitly upcast to Object. If the items are value types, they must be boxed when they are added to the list, and unboxed when they are retrieved. Both the casting and the boxing and unboxing operations decrease performance

ArrayList list = new ArrayList();
list.Add(3);
list.Add("It is raining in Redmond.");
int t = 0;
foreach (int x in list)
{
t += x;
}

This will cause a programming error, and this error will not be detected until runtime.


In the generic List<T> collection, the same operation of adding items to the collection
List<int> list1 = new List<int>();
list1.Add(3);
list1.Add("It is raining in Redmond."); // this gives Compile-time error.

Now you can create a list that is not only safer than ArrayList, but also significantly faster, especially when the list items are value types.

Is This Answer Correct ?    2 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Differentiate strong typing and weak typing

524


What are session state modes?

562


Let's say I have an existing application written using vb6 and this application utilizes windows 2000 com+ transaction services. How would you approach migrating this application to.net?

501


What are the steps to follow to host a web application on a web server?

589


What do you understand by aggregate dependency?

612






What is the current version of asp.net?

493


What is GAC in ASP.NET 2.0

581


What is form method?

491


What are the Types of chaching. How to implement caching

560


What is Razor View Engine

603


Are there any resources for drop-in replacements for the default css that comes with the ASP.NET Website template?

558


How to prevent client side validation from the ASP.NET validation controls?

571


Explain what is viewstate?

541


What are validator? Name the validation controls in asp.net? How do you disable them? Will the asp.net validators run in server side or client side? How do you do client-side validation in .net? How to disable validator control by client side javascript?

551


Explain how asp.net different from asp?

553