Skip to main content

Posts

Showing posts from August, 2020

Generics in C#

Generics Explained in C# Generic  is a type that is used to define a class , structure , interface or method with placeholders (type parameters) to indicate that they can store or use one or more of the types. In c#, the compiler will replace placeholders with the specified type at compile time.   Mostly we use generics with  collections  and the  methods  that operate on them to specify a type of objects to be stored in a  collection . The generics are introduced in .NET Framework 2.0 with a new  namespace  called  System.Collections.Generic .    Generics are useful to improve the code reusability, type safety, and the performance when compared with the  non-generic types  such as  arraylist .   Generics Declaration in C# To define a  class  or  method  as generic, then we need to use a type parameter as a placeholder with an angle ( <> ) brackets.   The fo...