Question:
Learn about C# generic?
balachandar P
2008-12-25 23:54:28 UTC
It is advance of c#. i want to learn c# generic.....
Three answers:
Smutty
2008-12-26 06:35:46 UTC
A generic type is a single programming element that adapts to perform the same functionality for a variety of data types. When you define a generic class or procedure, you do not have to define a separate version for each data type for which you may want

to perform that functionality.



Generic types were introduced in version 2.0 of the .NET Framework, and make it possible to design classes, structures, interfaces, and methods that defer the specification of one or more types until client code declares and instantiates the class or method. For example, by using a generic type parameter, you can write a single class that other client code can use without the cost or risk of CLR casts or boxing operations.



A type definition that takes type parameters is called a generic type. You can define and use generic classes, structures, interfaces, methods, and delegates



Generic types are designated by the syntax ClassName (C#) or ClassName(Of T) (Visual Basic), where T represents a data type that the client code must specify when it uses the generic class.



Generic types have the following advantages over nongeneric types:

1- Type safety. Generic types enforce compile-time type checking. Types that are based on System.Object accept any data type, and you must write code to check whether an input data type is acceptable. With generic types, the compiler can catch type

mismatches before run time

2- Performance. Generic types do not have to box and unbox data because each one is specialized for one data type. Operations that are based on System.Object must box input data types to convert them to System.Object and unbox data that is destined for output

3- Generic algorithms. Abstract algorithms that are type-independent are good candidates for generic types. For example, a generic procedure that sorts items by using the IComparable interface can be used with any data type that implements IComparable



Hope this helps.
?
2016-04-05 08:42:43 UTC
BobberKnob has the correct answer, I don't know what fool gave him a thumbs-down. You can learn any of those languages in any order you like. They are all based on C so they're very similar, although C++ and C# include important Object Oriented Programming features. But whichever one you learn first, the others will be easier to learn having the first one as a foundation. Kai has the correct answer also, but *asking* to be marked best answer is rather tacky. Why, Kai, are we desperate for Yahoo points? I can see giving a thumbs-down for that (but I didn't).
T3h Nigra
2008-12-26 01:15:22 UTC
???


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...