After seeing the previous example, you might wonder why we need generics when we can use the object type instead. The object type can be used for any type in C#, and the preceding example can be achieved through the use of an object type. Yes, the preceding example can be achieved through the use of the object type, but there won't be any type-safety. In contrast, generics ensure that the type-safety is there when the code gets executed.
If you are like me, you definitely want to know what type-safety is. Type-safety actually refers to keeping the type secure or unchangeable when executing any task in the program. This helps us reduce runtime errors.
Now, let's write the preceding program, using the object type instead of a generic, to see how generics can handle type-safety and object types can't:
using System;
using System.Collections.Generic...