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
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.