What are generics and what are generic collections?

Posted by Rajeshk under ASP.NET on 11/28/2012 | Points: 10 | Views : 1876 | Status : [Member] | Replies : 2
hi,
can anyone differentiate the generics and generic collections?

Thanks&Regards
rajeshkommireddy@gmail.com



Responses

Posted by: Pratyupalati on: 11/29/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,

Generics are classes, structures, interfaces, and methods that have placeholders (type parameters) for one or more of the types that they store or use. A generic collection class might use a type parameter as a placeholder for the type of objects that it stores; the type parameters appear as the types of its fields and the parameter types of its methods. A generic method might use its type parameter as the type of its return value or as the type of one of its formal parameters. The following code illustrates a simple generic class definition.
Example:
public class Generic<T>
{
public T Field;
}

Generic collections - These are the collections that can hold data of same type and we can decide what type of data that collections can hold.
Using generic collection classes provides increased type-safety and in some cases can provide better performance, especially when storing value types.

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

Posted by: aswinialuri-19361 on: 11/29/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,
Genrics:
Generics are the most powerful feature of C# 2.0. Generics allow you to define type-safe data structures, without committing to actual data types. This results in a significant performance boost and higher quality code, because you get to reuse data processing algorithms without duplicating type-specific code. In concept, generics are similar to C++ templates, but are drastically different in implementation and capabilities. This article discusses the problem space generics address, how they are implemented, the benefits of the programming model, and unique innovations, such as constrains, generic methods and delegates, and generic inheritance. You will also see how generics are utilized in other areas of the .NET Framework such as reflection, arrays, collections, serialization, and remoting, and how to improve on the basic offering.

Genric Collection:
Generic collections give you the best of all worlds with the strong typing of arrays and flexibility of non-generic collections. There are many more generic collections to choose from also, such as Stack, Queue, and SortedDictionary. Look in the System.Collections.Generic namespace for other generic collections.

Thanks & Regards
Aswini Aluri



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

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

Login to post response