如何拆分()分隔字符串列表<字符串>字符串、列表、GT、LT

由网友(女人阿丶沵让哥情何以堪﹌)分享简介:我有这个code:String[] lineElements; . . .try{using (StreamReader sr = new StreamReader("TestFile.txt")){String line;while ((line = sr.ReadLine()) != null){lin...

我有这个code:

    String[] lineElements;       
    . . .
    try
    {
        using (StreamReader sr = new StreamReader("TestFile.txt"))
        {
            String line;
            while ((line = sr.ReadLine()) != null)
            {
                lineElements = line.Split(',');
                . . .

但后来想到也许我应该去同一个列表来代替。但是,这code:

but then thought I should maybe go with a List instead. But this code:

    List<String> listStrLineElements;
    . . .
    try
    {
        using (StreamReader sr = new StreamReader("TestFile.txt"))
        {
            String line;
            while ((line = sr.ReadLine()) != null)
            {
                listStrLineElements = line.Split(',');
. . .

...给我,无法隐式转换类型字符串[]'到'System.Collections.Generic.List的

推荐答案

string.Split()返回数组 - 你可以用它转换成一个列表了ToList()

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

listStrLineElements = line.Split(',').ToList();
阅读全文

相关推荐

最新文章