Generics

Definition & Meaning

Last updated 23 month ago

What are Generics in C#?

Generics check with a feature in C# that lets in defining a Class or approach with kind as a Parameter.

Generics allow for designing a classes and strategies whose sorts are specified handiest on the time of assertion and instantiation. This enables development of well-known lessons and techniques that help in improving perFormance, productivity and type-safety.

Generics are often used in creating Collection training for enforcing ideas which include lists, hash Tables, Queues, etc. These classes manipulate a hard and fast of gadgets and encapsulate operations that aren't unique to a specific facts type.

Generics also are referred to as Parametric Polymorphism.

What Does Generics Mean?

Generics had been introduced in C# 2.Zero as a part of Common Language Runtime of .NET to conquer the difficulty in imposing generalization in in advance versions. Generalization turned into done with the aid of Casting kinds to and from regular base kind, SySTEM.Object that cHanged into now not type-secure and required casting, which ends up in successful to overall performance.

Some of the benefits in the usage of generics consist of:

  • Casting isn't always required for getting Access to each element inside the series
  • Client Code that uses generics is kind-secure at some point of execution via prEventing the usage of facts whose kind is different from the one used within the Statement
  • Code is not duplicated for more than one varieties of Data

The List<T> series elegance is an example for frequent magNiFicence supplied in the .NET Framework Class Library that can be used to add, delete and seek an object of any kind (T) that is exceeded as parameter to it. When the List elegance is Instantiated with a type parameter in the client code, it would be similar to a concrete magnificence implemented with same kind.

Generics are just like C Templates in concept but Range especially in Implementation.

Share Generics article on social networks

Your Score to Generics article

Score: 5 out of 5 (1 voters)

Be the first to comment on the Generics

4394- V4

tech-term.com© 2023 All rights reserved