2011-07-05 1 views

답변

57
string s = "1,5,7"; 
int[] nums = Array.ConvertAll(s.Split(','), int.Parse); 

또는, LINQ-Y 버전 :

int[] nums = s.Split(',').Select(int.Parse).ToArray(); 

그러나 처음에는 조그마한 비트 빠를 것이다.

+0

와우, 당신은 O_O ... 매일 새로운 것을 배울 –

4

여기 있습니다.

string numbers = "1,5,7"; 
List<int> numlist = new List<int>(); 

foreach (string number in numbers.Split(',')) 
    numlist.Add(Int32.Parse(number)); 
6
string numbers = "1,5,7"; 
string[] pieces = numbers.Split(new string[] { "," }, 
            StringSplitOptions.None); 

int[] array2 = new int[pieces.length]; 

for(int i=0; i<pieces.length; i++) 
    array2[i] = Convert.ToInt32(pieces[i]); 
관련 문제