Why do we need Generic Methods [Resolved]

Posted by Gayathri under C# on 6/25/2013 | Points: 10 | Views : 1438 | Status : [Member] | Replies : 2
why do we write a Generic method
why not is it enough to return Generic type alone?
i know why we use generic concepts in C#
and the differnece betwene using arraylist and Generic


But this Generic Methods has been a difficult thing to understand
somebody help me the process behind that ..like forexample Arraylist works out with the cost of upcasting to object.
so like that is there any advantage in using generic methods.




Responses

Posted by: aswinialuri-19361 on: 6/25/2013 [Member] Starter | Points: 50

Up
0
Down

Resolved
hi Gayithri,

generic collections are used to hold any type of objects and also provide type safe code
in c#.net 1.0 we can declare a reference type and value type
in c#.net 2.0 it allows type defining type safe data structure without committing to actual datatype
it can both value type and reference type in such situations we can use generic collections.
examp le:
public class cls<t>
{
public t obj;
}
in page load
cls<int> obj1=new cls<int>();
obj1 .obj=1;
cls<string> obj2=new cls<string>();
obj2.obj="aswini"


Mark as Answer if it helps you
Thanks&Regards
Aswini Aluri

Gayathri, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Gayathri on: 6/25/2013 [Member] Starter | Points: 25

Up
0
Down
thanks aswini

Gayathri, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response