2
Answers

Generics in Dotnet Framework

Photo of Kiran Kumar

Kiran Kumar

2w
162
1

What are Generics in  Dotnet Framework with c# example

Answers (2)

0
Photo of Rajanikant Hawaldar
32 38.8k 456.5k 2w

Refer below articles/blog

https://www.c-sharpcorner.com/UploadFile/84c85b/using-generics-with-C-Sharp/

https://www.c-sharpcorner.com/article/generics-in-C-Sharp3/

0
Photo of Sangeetha S
218 8.7k 323.9k 2w

Generics in the .NET Framework are a powerful feature that allow you to define classes, interfaces, and methods with a placeholder for the data type. This enables type safetycode reusability, and performance improvements by avoiding boxing/unboxing and type casting.

 Why Use Generics?

  1. Type Safety: Errors are caught at compile time rather than runtime.
  2. Performance: Avoids boxing/unboxing for value types.
  3. Code Reusability: Write a single class or method that works with any data type.

 Built-in Generic Types

  • List<T>
  • Dictionary<TKey, TValue>
  • Queue<T>Stack<T>
  • Nullable<T> (for value types)