Mega Code Archive

 
Categories / C# Book / 03 Collections
 

0352 Array Conversion

The following converts an array of floats to an array of integers: using System; using System.Collections; class Sample { public static void Main() { float[] reals = { 1.3f, 1.5f, 1.8f }; int[] wholes = Array.ConvertAll(reals, r => Convert.ToInt32(r)); Array.ForEach(wholes, Console.WriteLine); } } The output: 1 2 2