我有这个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();
上一篇:C#中的MemoryStream VS字节数组数组、字节、MemoryStream、VS
下一篇:句柄ClassCastException:无法将ViewComponentManager$FragmentConextWrapper强制转换为AppCompatActivity句柄、转换为、Class