Working with List Generic collection Properties and Methods Part - 1

Rajesh_Kumar
Posted by Rajesh_Kumar under C# category on | Points: 40 | Views : 624
using System.Collections.Generic;
Methods:-
1). ADD: This is used for adding items into List.

List<string> lst_courses = new List<string>();
lst_courses.Add("C#");
lst_courses.Add("VB.Net");
lst_courses.Add("ASP.NET");
lst_courses.Add("SQL-Server");

2).Clear: This is used for clearing all the items from List.

lst_courses.Clear();

3). Contains: Is used for checking where List has Items or not.
if (lst_courses.Contains("SQL-Server"))
{
value = true;
}
else
{
value = false;
}

Properties:-
1).Count: Tnis is used for Counting no of items in a list.
int no_of_items = lst_courses.Count;

2).Capacity:
Used for setting total number of elements in a List.

lst_courses.Capacity = 10;

Comments or Responses

Login to post response