How can I convert a text file into a list of int arrays

后端 未结 5 2044
温柔的废话
温柔的废话 2021-01-16 19:02

I have a text file containing the following content:

0 0 1 0 3 
0 0 1 1 3 
0 0 1 2 3 
0 0 3 0 1 
0 0 0 1 2 1 1 
0 0 1 0 3 
0 0 1 1 3 
0 0 1 2 3 
0 0 3 0 1 
0         


        
5条回答
  •  既然无缘
    2021-01-16 19:47

    var resultList = new List();
    File.ReadAllLines("filepath") 
        .ToList()
        .ForEach((line) => {
                                var numbers = line.Split()
                                                  .Select(c => Convert.ToInt32(c));
                                resultList.AddRange(numbers); 
                            });
    

提交回复
热议问题