Generics types

Generics allow us to design classes and methods without the notion of data types. In simpler terms, when we talk about methods, generics allow us to define methods without specifying the type of the input variables.

Let's go through the following code implementation and see how it can help us. In the following example, we have created a function that compares the values between two int variables, A and B. If the value is the same, it returns true; however, if the value is not same, it returns false:

static private bool IsEqual(int A, int B){     if(A== B)     {         return true;     }     else     {         return false;     } }

Now, let's say we try to pass a variable with a data type that is not int. In the following screenshot, we are trying to pass string ...

Get Programming in C#: Exam 70-483 (MCSD) Guide 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.