Saturday, 12 January 2013 14:54

List in asp.net

Written by 
Rate this item
(0 votes)

List<> can be used as a collection of objects which
can be accessed by index.List originated from
System.Collections.Generic class.List objects can
be sorted,searched,manipulated.so List is very
useful in programming for holding any type of
objects.following shows a example of List<> -

first create a variable of List<> type

List<String> Res = new List<String>();

following way string objects are added to the List -

SqlConnection Conn = new SqlConnection(ConnectionString);
SqlCommand Cmd = new SqlCommand("SELECT CName FROM Categories", Conn);

Conn.Open();
SqlDataReader Categories = Cmd.ExecuteReader();

while (Categories.Read())
Res.Add(Categories.GetString(0));

Read 3115 times
Super User

Email This email address is being protected from spambots. You need JavaScript enabled to view it.

Latest discussions

  • No posts to display.