| Dua Ali
In this blog, a tutorial is demonstrated to learn that what are Generic classes in C#? Generic classes in C# have type parameters. This becomes part of the class definition itself. In this demo, a generic class of type T is used for the parameters. The letter T denotes a type that is only known based on the calling of the method.
To implement an example for better understanding, Open Visual Studio. Select the project type as console application.
![GenericClassCSharp](/images/Dua/GenericClassCSharp/Generic Class in CSharp-0.png)
Give project a name then click on Next then on Create.
![GenericClassCSharp](/images/Dua/GenericClassCSharp/Generic Class in CSharp-1.png)
Here, a simple class is created named ‘DemoClass’ in which we can see that the parameters are not any specific data type, instead a generic type T is used which allows you to create the object of this class with any data type.
![GenericClassCSharp](/images/Dua/GenericClassCSharp/Generic Class in CSharp-2.png)
In the Main class, we have created an object of our previous class with string data type. Using this object, a method is called by passing two strings in the parameters.
![GenericClassCSharp](/images/Dua/GenericClassCSharp/Generic Class in CSharp-3.png)
The function runs successfully and returns the result as we had provided matching strings.
![GenericClassCSharp](/images/Dua/GenericClassCSharp/Generic Class in CSharp-4.png)
Here, we have tried with non-matching strings using the same object of type string.
![GenericClassCSharp](/images/Dua/GenericClassCSharp/Generic Class in CSharp-5.png)
As the two strings were not matching, we have got the following output.
![GenericClassCSharp](/images/Dua/GenericClassCSharp/Generic Class in CSharp-6.png)
The generic class allows us to create object of different types using the same class. Here we have created an object using integer data type with same class. The same method worked right with integer type parameters as shown in the console window.
![GenericClassCSharp](/images/Dua/GenericClassCSharp/Generic Class in CSharp-7.png)
Join us next time, as we continue our journey of learning canvas apps.Click here to learn more about Imperium's Power Apps Services. We hope this information was useful, and we look forward to sharing more insights into the Power Platform world.