,
Share with your friends 

Working With Generic List Class in C# 3.0

3 ratings Views 199 
Author: Hefin (Hefin Dsouza)  View Profile |  View other solutions by this author

Question / Problem


Working with the Generic List Object of the System.Collections.Generic Namespace.What are its benifits?

Solution

The Below Example Shows How to work with A Generic List Class Which is more powerfull than the ArrayList Class.It is a Type safe Collection Type.

Example :
using System;
using System.Collections.Generic;
class Program
{
static void Main(string[] args)
{
List< string > names = new List< string >();
names.Add("Hefin");
names.Add("Abbas");
names.Add("Rinso");
names.Add("Freshore");
names.Add("Sachin");

List<int> ID = new List<int>();
ID.Add(1);
ID.Add(2);
ID.Add(3);
ID.Add(4);
}
}
This is an Type Safe Version of an Array List
In This Example the List Object names will accept only string values and The List object ID only accepts Int values.

Example :
using System;
using System.Collections.Generic;
class Program
{
static void Main(string[] args)
{
List< string > names = new List< string >();
names.Add("Hefin");
names.Add("Abbas");
names.Add("Rinso");
names.Add("Freshore");
names.Add("Sachin");

List<int> ID = new List<int>();
ID.Add(1);
ID.Add(2);
ID.Add(3);
ID.Add(4);
}
}
This is an Type Safe Version of an Array List
In This Example the List Object names will accept only string values and The List object ID only accepts Int values.
Regards
Hefin Dsouza


Applies to

.Net Framework 3.5

Rank It

Login to rank it

Report


Advertisement