Possible Duplicate:
Convert ArrayList into string array(string[]) in c#
How can I convert array list to string[]?below is code I am trying. I am getting an error:
At least one element in the source array could not be cast down to the destination array type.
ArrayList myArrayList = new ArrayList();
foreach (DataRow dtRow in DtSet.Tables[0].Rows)
{
myArrayList.Add(dtRow);
}
string[] myStringArray = (string[])myArrayList.ToArray(typeof(string));
List<T>instead of anArrayList?DataRow. It is telling you it can't cast aDataRowto astring. Which is entirely correct; aDataRowis not astring...DateRow.ToString()would callObject.ToString()which is implemented asthis.GetType().ToString(). What you can do is cast every field in every datarow to string and join these fields.