Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 13-02-2011
Member
 
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.
Reply With Quote
  #2  
Old 13-02-2011
Member
 
Join Date: Apr 2009
Posts: 484
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 + +;

        }

   }
Reply With Quote
  #3  
Old 13-02-2011
Member
 
Join Date: May 2009
Posts: 533
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.
Reply With Quote
  #4  
Old 13-02-2011
Member
 
Join Date: May 2009
Posts: 532
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.
Reply With Quote
  #5  
Old 16-02-2011
Member
 
Join Date: Apr 2009
Posts: 567
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.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Creating a generic class in dot net"
Thread Thread Starter Forum Replies Last Post
Upgrade Sony Ericsson Xperia Play Micro SD card from class 2 8GB to class 4 32GB Aaryan2011 Portable Devices 8 08-10-2011 11:06 PM
Creating a vector type of a class Xmen Software Development 5 24-02-2010 03:38 AM
Creating graphical ftp client with Perl using class NET:: FTP Udayachal Software Development 6 16-02-2010 01:43 AM
Gauge Class for creating Volume Bar Adrina_g Software Development 3 10-12-2009 09:57 AM
Creating an array from a class Kingfisher Software Development 3 25-11-2009 02:50 PM


All times are GMT +5.5. The time now is 03:47 AM.