1. Back To Blog

What is generics and have you ever used any generic classes? ( .NET Generic Interview questions)

Generics- In simple terms we will define it as General type of programming.


Rather defining something for specific types we will create it in general manner which will work for multiple types.


Let's have an example.

public T Add(T x ,T y)

return (T)(x+y);



Int x=Add(5,6);

float y=Add(5.2,6.3);

string s=Add("Sukesh","Marla");


In technical terms, we will create something (class or function) in such a way that while developing we won't specify the type for which we are creating rather while end developer when actually use it will specify the type.

Examples for generic class:

Yes, I do have used List and Dictionary.

Can you give me the example how you used them?

List x=new List();

x.add(new Customer()Name="A"});

x.add(new Customer()Name="B"});

Dictionary y=new Dictionary();

y.add(1,"Mr A");

y.add(2,"Mr B");


Below is an awesome C# Generic interview questions with answers video provided by questpond.com



Shiv Prasad Koirala

Visit us @ www.questpond.com or call us at 022-66752917... read more

We are on Social