Results 1 to 6 of 6

Thread: Don't know about Generic Types in C#

  1. #1
    Join Date
    Dec 2009
    Posts
    41

    Don't know about Generic Types in C#

    Hi friend,

    I have to discuss one of my query regarding the C sharp concept with you. I know C sharp has support to .Net framework. I am unable to understand the 'Generic Types' of C sharp. I wonder if you are able to provide some details about the 'Generic Types' in C#. I t will be be great if you will provide suitable example for the same. I will greatly appreciate you help 'Generic Types'.

  2. #2
    Join Date
    Feb 2008
    Posts
    1,852

    Re: Don't know about Generic Types in C#

    Hi,

    A generic type is actually a type not specified in the implementation of a method or class. The type will be determined using this method or class. In fact, for each different type used, the compiler will generate a new version of the method or class. Generic types are used to perform the same treatment on different types of data. It is possible to use more generic types for a method or class.

  3. #3
    Join Date
    Jan 2008
    Posts
    1,521

    Re: Don't know about Generic Types in C#

    Generic types are identified by name, and specified between the signs < and > placed just after the method name or class. Consider a static method returning the maximum value between two values passed as a parameters. The compiler determines the type used for TQ from the values of arguments:
    Code:
    Public static TQ max<TQ>(TQ, Tb) 
    {
        return has > bf ? has : bf ;
    }
     
    int integer = max ( 12 , 22 );
    double vmax = max (1.618,  3.14 , );

  4. #4
    Join Date
    May 2008
    Posts
    2,012

    Re: Don't know about Generic Types in C#

    In Generic Types of C#, it is possible to restrict the types used to those that implement some interface. It is possible to use class or struct to limit the type or class or structure. It is also possible to add constraints on manufacturers of generic type:
    Code:
    Public class TriableDemo <TOV>
        where TOV : new()  
    {
        Public Create TOV()
        {
            return new TOV(); 
        }
    }

  5. #5
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Don't know about Generic Types in C#

    The operator returns the default value of generic type which is specified. This is the value when a variable of this type is not initialized (0 for numbers, null for reference types).It is possible to define an alias for a specific generic class, using the keyword Using, Generic types are also usable with the structures. The compiler identifies the type which is used for values of the arguments.

  6. #6
    Join Date
    May 2008
    Posts
    2,297

    Re: Don't know about Generic Types in C#

    In generic type method, type parameters represent a placeholder for a specific type that a customer specifies when it instantiates a variable of the generic type. Name the generic type parameters with descriptive names, unless a name consisting of one letter is explicit and descriptive name would not add value. In each instances of Generic type in the class will be replaced at run time with the type argument. By this substitution, three distinct objects of type safe and effective with a single class definition can be created.

Similar Threads

  1. Types of CRM
    By Vicky Woodley in forum Education Career and Job Discussions
    Replies: 5
    Last Post: 18-11-2010, 08:39 AM
  2. Multiple generic types in java
    By Maya Angelou in forum Software Development
    Replies: 5
    Last Post: 11-03-2010, 01:11 PM
  3. Different types of RAM
    By Eleeazar in forum Hardware Peripherals
    Replies: 3
    Last Post: 25-11-2009, 02:49 AM
  4. Different types Types CCFL's
    By Zipp in forum Overclocking & Computer Modification
    Replies: 3
    Last Post: 29-10-2009, 09:11 AM
  5. Different RAM types and its uses
    By eliotmc in forum Hardware Peripherals
    Replies: 2
    Last Post: 13-10-2008, 01:57 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,149,246.43617 seconds with 17 queries