How to convert string with numbers to int array in C#

1 Answer

0 votes
using System;

public class Program
{
    public static void Main()
    {
        string str = "4,6,79,8,100,2,0,9,1081";

        int[] arr = Array.ConvertAll(str.Split(','), s => int.Parse(s));

        foreach (var item in arr)
            Console.WriteLine(item);
    }
}





/*
run:

4
6
79
8
100
2
0
9
1081

*/

 



answered Sep 3, 2022 by avibootz

Related questions

1 answer 184 views
1 answer 96 views
1 answer 227 views
1 answer 414 views
...