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

I M working in 1.1 .net framework. In a page I have 5 text box & 2 data grid. In PageLoad() All text box will populate with blank value & 1st dataGrid with some value. When I click on EDIT button Of the 1st dataGrid,The Relevent data Of the particular row will populate in first 3 textboxs & corresponding relevent data Will populate in the 2nd DataGrid. Now when I click 2nd datagrid's EDIT button of a perticular Row,relevent data will populate on last 2 textboxs & 1st 3 textbox's value will be same as per as it was........ ........My Problem Is ........... When I click on edit button Of 2nd DataGrid, 1st 3 text boxes values goes Off & 2nd DataGrid Is goes off Due to Postback.but The relevent value is populated In last 2 textboxes.So How I stoped this postback??So that all the data in 1st 3 textboxes will be same.So that I can edit the values of 2nd Grid with 1st 3 textBoxes value.. plz dirctly mail me 1 copy of post to... maloy.adhikari@in.com

2 Answers  


Which is better asp.net or php?

0 Answers  


How can we prepairing Interview

0 Answers   ITcom, TCS,


How many ways are there to maintain a state in .net? What is view state?

0 Answers  


What is IPostBack? How to use it?

0 Answers   MCN Solutions,






Give a few examples of page life cycle events.

0 Answers   Accenture,


State Management (viewstate, session etc)

2 Answers   Syntel,


List the asp.net validation controls?

0 Answers  


Explain method to handle error using HttpError in Web API?

0 Answers  


what is session . how it is use ?

3 Answers   TCS,


Which is better union or union all?

0 Answers  


Explain how inline and code behind is used differently ?

1 Answers   Siebel,


Categories