Saturday, September 18, 2010

Diffrences between Array and ArrayList.

1) The capacity of an Array is fixed. Where as, ArrayList can increase and decrease size dynamically.
2) An Array is a collection of similar items. Where as, ArrayList can hold item of different types.
3) Array is in the System namespace. Where as, ArrayList is in the System.Collections namespace.
4) An Array can have multiple dimensions. Where as, ArrayList always has exactly one dimension.
5) We can set the lower bound of an Array. Where as, The lower bound of an ArrayList is always zero.

Please check the following example:

ArrayList al = new ArrayList();
al.Add("1");
al.Add(2);
al.Add(new DateTime(2001, 4, 2));
foreach (object o in al)
{
Response.Write(o.ToString() + "
");
}

Friday, September 17, 2010

Remove Duplicate Records From a DataTable.

public DataTable DistinctRecordsFromDataTable(DataTable originalDT)
{
DataTable distinctDT = new DataTable();
DataView dv = originalDT.DefaultView;
System.Collections.Generic.List columns = new List();
//Add all the required columns which you want to get distinct to
//string list as follows
columns.Add("Column1");
columns.Add("Column2");
columns.Add("Column3");
columns.Add("Column4");
columns.Add("Column5");
distinctDT = dv.ToTable(true, columns.ToArray());
return distinctDT;
}

To Reset all of the controls of Form by one wrriting just one line.

you don't need to use loop or line by line of all controls to reset or clear them. You can just add the following code in your application: