Results 1 to 5 of 5

Thread: Creating a generic class in dot net

  1. #1
    Join Date
    Jan 2011
    Posts
    57

    Creating a generic class in dot net

    I am well aware about the concept of object oriented programming , right now am planning to develop applications on .NET languages , though I am still on the learning phase of developing applications on Microsoft Visual Studio , I want to learn web based applications , but there was a stage in the program that needed to create a generic class , can anyone explain me a bit about the generic class and the generic types.

  2. #2
    Join Date
    Apr 2009
    Posts
    488

    Re: Creating a generic class in dot net

    Generic class are a bit different from a non generic class , there is an advantage of using this generic class , once I was too coding and that required inclusion of declaring a property in my program , but fortunately I did not require to set the values of properties , it was done in the constructor of the generic class .

    using System;
    using System.Collections.Generic;
    using System.Text;
    public class GenericList

    Code:
    {
    
            private  object[] elements;
    
            private int cnt; 
    
            public GenList()
    
            {
    
                elmnts = new object[10];
    
            }
    
            public object this[int index]
    
            {
    
                get { return elmnts[index]; }
    
                set { elements[index] = val; }
    
            } 
    
            public void Add (object param)
    
            {
    
                if (cnt == elmnts.Length)
    
                {
    
                      // Increase the
    
                      object[] tempArr = null ;
    
                      elmnts.CopyTo(tempArr,0);
    
                      elmnts = new object[cnt * 2];
    
                      elmnts = tempArr;                             
    
                }
    
                elmnts[cnt] = param;
    
                cnt = cnt + +;
    
            }
    
       }

  3. #3
    Join Date
    May 2009
    Posts
    543

    Re: Creating a generic class in dot net

    Generics are the most influential feature of C# 2.0. It permits defining type-safe data structures, without committing to real data types. In C# 1.0 we can also declare reference type or there is also an value type. But in the majority of the application we go through situation where we require type that can hold both reference & value type. In such circumstances we make use of generic types.

  4. #4
    Join Date
    May 2009
    Posts
    539

    Re: Creating a generic class in dot net

    Generics are the most influential feature of C# 2.0. It permits defining type-safe data structures, without committing to real data types. In C# 1.0 we can also declare reference type or there is also an value type. But in the majority of the application we go through situation where we require type that can hold both reference & value type. In such circumstances we make use of generic types.

  5. #5
    Join Date
    Apr 2009
    Posts
    569

    Re: Creating a generic class in dot net

    I can tell you a bit about generic methods , What remains is to describe all other characteristics in terms of the parameterized type as required. This may comprise properties, methods, and events. For instance, everywhere we can take an example , if in any program anything is repeatredmultiple occasions we can use this feature, suppose Customer appears, we make use of a parameter T in its place . We create custom list The completed generic List class is shown in Listing 4.To test the custom list, we comment out the using statement for the System.Collections.Genericnamespace and make use of List<T> if we have made use of any list .It's worth to make a note that .NET's List<T> is completely evolved and includes many more features than our sample, and makes and we can see in its programs how it makes easy the mechanics are for defining custom generic classes.

Similar Threads

  1. Replies: 8
    Last Post: 08-10-2011, 11:06 PM
  2. Creating a vector type of a class
    By Xmen in forum Software Development
    Replies: 5
    Last Post: 24-02-2010, 03:38 AM
  3. Creating graphical ftp client with Perl using class NET:: FTP
    By Udayachal in forum Software Development
    Replies: 6
    Last Post: 16-02-2010, 01:43 AM
  4. Gauge Class for creating Volume Bar
    By Adrina_g in forum Software Development
    Replies: 3
    Last Post: 10-12-2009, 09:57 AM
  5. Creating an array from a class
    By Kingfisher in forum Software Development
    Replies: 3
    Last Post: 25-11-2009, 02:50 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,713,556,077.83634 seconds with 17 queries