How to split() a delimited string to a List

前端 未结 7 2317
被撕碎了的回忆
被撕碎了的回忆 2020-12-04 11:30

I had this code:

    String[] lineElements;       
    . . .
    try
    {
        using (StreamReader sr = new StreamReader(\"TestFile.txt\"))
        {
            


        
相关标签:
7条回答
  • 2020-12-04 12:27

    string.Split() returns an array - you can convert it to a list using ToList():

    listStrLineElements = line.Split(',').ToList();
    

    Note that you need to import System.Linq to access the .ToList() function.

    0 讨论(0)
提交回复
热议问题