What is Generic? explain clearly?

Answers were Sorted based on User's Feedback



What is Generic? explain clearly?..

Answer / 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

What is Generic? explain clearly?..

Answer / dhanunjaya

generic is a general data type in c# similar to template in
c++.by using generic we can assign any type of value to the
generic variable.we have generic methods,generic classes
also.

Is This Answer Correct ?    2 Yes 2 No

What is Generic? explain clearly?..

Answer / tejkrishna

Generics are the type like list<> collection but it can
contain any type within it like list<t>.

Is This Answer Correct ?    1 Yes 1 No

Post New Answer

More ASP.NET Interview Questions

please give a brief knowledge about these events ? page_render() page_prerender() page_unload page_loadcomplete page_preinit

1 Answers   Netsweeper,


Have u used webcontrols?Tell me something about these?

2 Answers   Microsoft,


view state data is stored in which format?

15 Answers   Mind Tree, Pratham Software,


Describe in brief .net framework and its components.

0 Answers  


How to you can limit Access to Web API to Specific HTTP Verb?

0 Answers  






Explain about Automatic resource management?

0 Answers  


What are the new data controls in asp.net 2.0?

0 Answers  


Differentiate between a hyperlink control and a linkbutton control.

0 Answers  


What are validator? Name the validation controls in asp.net? How do you disable them?

0 Answers  


How to handle errors in Web API?

0 Answers  


What are the validation controls available in ASP.NET?

0 Answers  


Difference between datagrid and datareader?

1 Answers  


Categories