Generic in C#

Here we are going to learn about the Generic in C# and how it can works.
  • 3434

Introduction
 

Firstly we required to understand what is the Generic classes and why we use the Generic classes. Mainly Generic classes are the type of parameter. In the period of programming there is a situation whenever we have to hold both kind of value type and reference type. Solution of this kind of problem is the Generic classes. This is a technique to specifies the class without declared the data type. Different kind of the data type can be used in the Generic classes. We will use two type of parameters in the programming language in the below example.

Reference type of parameters are interface,arrays,strings and classes.
Value type of parameters are structures,enums,primitive.
 
 Example of the generic classes
 

 public class genrc
 
{
 public static void Main()
 {
   Int32 a = 10, b = 0;
   b = a;
   a++;
   Console.WriteLine("a value:{0},b value {1}", a, b);
   Console.ReadLine();
 }
 }
 
 
Output of the generic example

genric.jpg

© 2020 DotNetHeaven. All rights reserved.