Syntax:
Array.ConvertAll<TInput, TOutput> Method (TInput[], Converter<TInput, TOutput>)
It converts an array of one type to an array of another type.
Example:
In the following example we have two class InputClass and OutputClass , one method ConvertArrayObject that will convert array of InputClass to array of OutputClass.
public class InputClass {
public int id { get; set; }
public string name { get; set; }
}
public class OutputClass {
public string myId { get; set; }
public string myName { get; set; }
}
public OutputClass[] ConvertArrayObject(InputClass[] inputArray) {
return
System.Array.ConvertAll<InputClass, OutputClass>(inputArray, (elem) => {
return new OutputClass {
myId = elem.id.ToString(),
myName = elem.name
};
});
}
Posted On:
14-Apr-2016 00:38