Change String Array To Int Array - CSharp System

CSharp examples for System:String Format

Description

Change String Array To Int Array

Demo Code


using System.Globalization;
using System.Text;
using System.Collections.Generic;
using System;/*from w  w w . ja va2  s  .co  m*/

public class Main{
        /// <summary>
        /// </summary>
        /// <param name="beChangeArray">
        /// The be change array.
        /// </param>
        /// <returns>
        /// </returns>
        public static int[] ChangeStringArrayToIntArray(string[] beChangeArray)
        {
            if (beChangeArray == null) return new int[0];

            int[] intList = new int[beChangeArray.Length];
            int I = 0;
            int tempInt = 0;

            foreach (string curStr in beChangeArray)
            {
                intList[I] = 0;
                tempInt = 0;
                if (int.TryParse(curStr, out tempInt))
                {
                    intList[I] = tempInt;
                }
                I++;
            }

            return intList;
        }
}

Related Tutorials