Stacked Stacked - 1 month ago 13
C# Question

C# Array.ConvertAll for compact framework

As far as I know there is no Array.ConvertAll() for the compact framework. What is the best way to do an Array.ConvertAll in the CF?

public static string DataRowToString(DataRow dr)
{
return dr["columns"].ToString();
}

public static string[] DataTableToArray(DataTable dt)
{
var dr = dt.Select();
string[] strArr = Array.ConvertAll(dr, new System.Converter<DataRow, string>(DataRowToString));
return strArr;
}


The code above doesn't work in CF.

Answer

You can use a LINQ expression:

var result = input.Select(converter).ToArray();