© Vaskaran Sarcar 2018
Vaskaran SarcarInteractive C#https://doi.org/10.1007/978-1-4842-3339-9_12

12. Generics

Vaskaran Sarcar
(1)
560066 Bangalore, Karnataka, India
 

Comparison between Generic and Non-Generic Programs

Teacher starts the discussion: Generics are one of the key concepts of C#. They came in C# 2.0, and since then, they have expanded with additional features.
To understand the power of generics , we will start with a non-generic program and then write a generic program. Later, we will do a comparative analysis and then we will try to discover the advantages of generic programming. Consider the following program and the output.

Demonstration 1: A Non-Generic Program

using System;
namespace NonGenericEx
{
    class NonGenericEx
    {
        public ...

Get Interactive C#: Fundamentals, Core Concepts and Patterns now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.