Manas Ranjan Dash
Why is Generics so important?
By Manas Ranjan Dash in ASP.NET on Jul 22 2010
  • suma chowdary
    Jul, 2010 31

    Generics are a new feature in version 2.0 of the C# language and the common language runtime (CLR). Generics introduce to the .NET Framework the concept of type parameters, which make it possible to design classes and methods that defer the specification of one or more types until the class or method is declared and instantiated by client code. For example, by using a generic type parameter T you can write a single class that other client code can use without incurring the cost or risk of runtime casts or boxing operations

    Sample :-
    // Declare the generic class
    public class GenericList<T>
    {
    void Add(T input) { }
    }
    class TestGenericList
    {
    private class ExampleClass { }
    static void Main()
    {
    // Declare a list of type int
    GenericList<int> list1 = new GenericList<int>();

    // Declare a list of type string
    GenericList<string> list2 = new GenericList<string>();

    // Declare a list of type ExampleClass
    GenericList<ExampleClass> list3 = new GenericList<ExampleClass>();
    }
    }

    See more help :-
    http://www.csharpfriends.com/Articles/getArticle.aspx?articleID=370
    http://www.c-sharpcorner.com/UploadFile/sdhar8po/GenericsInCSharp11152005055344AM/GenericsInCSharp.aspx
    http://www.knowdotnet.com/articles/generics101.html

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS