Convert String To List Int - CSharp System.Collections.Generic

CSharp examples for System.Collections.Generic:List

Description

Convert String To List Int

Demo Code


using System.Reflection;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;/*  w w w .ja  va 2s.  com*/

public class Main{
        public static List<int> ConvertStringToListInt(string strInput, char strSplitCondition)
        {
            List<int> ret = new List<int>();
            if (strInput != null)
            {
                string[] strTmp = strInput.Split(strSplitCondition);
                int tmp;
                foreach (var item in strTmp)
                {
                    try
                    {
                        tmp = Convert.ToInt32(item);
                        ret.Add(tmp);
                    }
                    catch (Exception ex) { ex.ToString(); }
                }
            }

            return ret;
        }
}

Related Tutorials