I am selecting data from a Datatable using Linq. Selection will be a column and requirement is functions should return string[]. I am not getting how to do convert results in to string[].
Please guide, below is my code:
public string[] GetCompletionList(string prefixText)
{
if (HttpContext.Current.Cache["Dir"] == null)
{
return null;
}
DataTable dt = (DataTable)HttpContext.Current.Cache["Dir"];
var details = from addresses in dt.AsEnumerable()
where SqlMethods.Like(prefixText, prefixText + "%") || SqlMethods.Like(prefixText, "%" + prefixText + "%")
select addresses["Details"];
return details.tol;
}
If each item in
detailsis already a string simply useIEnumerable<T>.ToArray():If you need to convert it first (in my example I am using
ToString()), you can useSelectto project each item to a string: