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.
Post A Comment:
0 comments: