Learn about Generics classes in C#

Learn how to use Generics in C# programming through Free .Net Tutorials

Hope you must have gone through my previous two articles regarding Class members and inheritance interfaces. Now, we’ll have a focus on Generics. Generics are nothing but the type parameters which are being used by interfaces, Classes, structures, and methods in .NET to define categories of objects that they can store or utilize. The most genuine illustration of generics is a collection, where you can mention the type of objects to be stored in a collection.

Codes To define a generic class:

public class TCGeneric<T>
    public T Field;

Codes to create an instance of a generic class:
var sampleTCObject = new TCGeneric<string>();
sampleTCObject.Field = "Technology Crowds";

Hope, the above codes will help you define and create a suitable Generic class perfectly in C# .Net programming. The interview candidates also could easily answer on this topic.

Anjan kant

Outstanding journey in Microsoft Technologies (ASP.Net, C#, SQL Programming, WPF, Silverlight, WCF etc.), client side technologies AngularJS, KnockoutJS, Javascript, Ajax Calls, Json and Hybrid apps etc. I love to devote free time in writing, blogging, social networking and adventurous life

Post A Comment: