C# List
C# List class is used to collection of values add,remove,count,index conditions represent . this access Int,String,bool like datatypes supports . list add to array values and display specific order.
List class is a collection and defined in the System.Collections.Generic namespace .
Code
List class add the int datatype values
List <int> li =new List<int>();
li.Add(100);
li.Add(200);
li.Add(300);
for (int i = 0; i < li.Count; i++)
{
Response.Write(li[i].ToString() + "<br/>");
}
Code
List class add the String datatype values
List <string> li =new List<string>();
li.Add("Dotnet");
li.Add("drizzles");
li.Add(".blogspot.in");
foreach (string str in li)
{
Response.Write(str.ToString());
}
Code
List class copy the Array values
//
Array copy to list
int[] arr=new int[3];
arr[0]=777;
arr[1] = 888;
arr[2] = 999;
List <int> li =new List<int>(arr); // arr copy to list
foreach (int Value in li)
{
Response.Write(Value.ToString() + ",");
}
Code
List class add the int datatype array values to display
List <int> li =new List<int>(new int[] {100,1000,1000}); // array
to list
for (int i = 0; i < li.Count;i++ )
{
Response.Write(li[i].ToString() + ",");
}
Code
List class check the indexof position for int,bool,string datatypes
List <int> li =new List<int>(new int[] {100,1000,1000}); // array
to list
List <bool> bo = new List<bool> (new bool[] {true,false});
List<string> str = new List<string>(new string[] { "Dotnet", "drizzles", ".blogspot.in" });
int index = li.IndexOf(1000);
Response.Write("Integer Index Position="+index + "<br/>");
int BoolIndex =bo.IndexOf(true);
Response.Write("Bool Index Position=" + BoolIndex + "<br/>");
int StrIndex = str.IndexOf(".blogspot.in");
Response.Write("String Index Position=" + StrIndex.ToString() + "<br/>");
Code
List class check the values contain from list using bool datatypes output:false
List <int> li =new List<int>();
li.Add(100);
li.Add(200);
li.Add(300);
bool Value=li.Contains(400);
Response.Write(Value.ToString() + "<br/>");
0 comments:
Post a Comment