public static System.Collections.Generic.List <U> CastArray <T, U>(System.Collections.Generic.List <T> a, U dummy) { return(a.ConvertAll(new Converter <T, U>((T x) => { return (U)(object)x; }))); // System.Collections.Generic.List<U> ret = new System.Collections.Generic.List<U>(); // foreach (var t in a) ret.Add((U)(object)t); // return ret; }
/// <summary> /// Convert a list of one type to an array of another type /// </summary> /// <typeparam name="L"></typeparam> /// <typeparam name="A"></typeparam> /// <param name="Items"></param> /// <param name="Conversion"></param> /// <returns></returns> /// <remarks></remarks> public static A[] ConvertListToArray <L, A>(System.Collections.Generic.List <L> Items, Converter <L, A> Conversion) { //Use converter delegate to convert list into another list System.Collections.Generic.List <A> ConvertedList = Items.ConvertAll(Conversion); //Create an array to hold the data A[] ReturnArray = new A[ConvertedList.Count]; //Copy the list to the array ConvertedList.CopyTo(ReturnArray); //All done return(ReturnArray); }
public string PrepareTableValues(System.Collections.Generic.List <Cell> LinqToExcel) { var HeaderString = LinqToExcel.ConvertAll <string>(new Converter <Cell, string>(CelltoString)); return("'" + string.Join("', '", HeaderString.ToArray()) + "'"); }