0

Why bother using generics when we can use var type? Im asking about c#

Hello guys I just wanted to know that why should we go through all that trouble and use generics when we can just use type var whenever we dont know what is the type of the variable that is going to be passed inside the method? Note that im asking about c#

11th Mar 2020, 4:05 PM
Emad
3 Answers
+ 4
Emad Always specify the language while posting a question so that it helps others to answer your question to the point, though the generic concept is pretty much the same in all languages.
11th Mar 2020, 4:10 PM
Avinesh
Avinesh - avatar
+ 2
Tnx alot Its Taken care of now
11th Mar 2020, 4:12 PM
Emad
0
var covers only primitive types, while with generics, you can type cast classes, other collections as well.. I guess, there may be other reason..
11th Mar 2020, 6:16 PM
Jayakrishna 🇼🇳