.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> Generics >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Working With Generic List Class in C# 3.0

Posted By:Hefin Dsouza       Posted Date: August 13, 2009    Points: 10    Category: Generics    URL: http://www.dotnetspark.com  
 

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


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 ID = new List();
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


     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend