Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/309.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 错误“无法隐式转换类型”System.Collections.Generic.IEnumerable'到“System.Collections.Generic.List”_C# - Fatal编程技术网

C# 错误“无法隐式转换类型”System.Collections.Generic.IEnumerable'到“System.Collections.Generic.List”

C# 错误“无法隐式转换类型”System.Collections.Generic.IEnumerable'到“System.Collections.Generic.List”,c#,C#,我正在尝试将数字列表转换为字符串,然后稍后再转换为列表。转换为字符串可以很好地工作,但当我将其转换回列表时,会出现错误,无法隐式转换类型“System.Collections.Generic.IEnumerable”。这是我正在运行的代码 using System; using System.Collections.Generic; using UnityEngine; using System.Linq; using System.Globalization; public class Te

我正在尝试将数字列表转换为字符串,然后稍后再转换为列表。转换为字符串可以很好地工作,但当我将其转换回列表时,会出现错误,无法隐式转换类型“System.Collections.Generic.IEnumerable”。这是我正在运行的代码

using System;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
using System.Globalization;

public class Test : MonoBehaviour
{

void Start()
{
    Function();
}

void Function()
{
    List<Int32> listBuffer= new List<Int32>();
    System.Random rnd = new System.Random();

    for (int x = 1; x < 100; x++)
    {
        listBuffer.Add(x);
    }

    List<Int32> listInt= (from item in listBuffer
                                      orderby rnd.Next()
                                      select item).ToList<Int32>();

    print(listInt[0]);

    string stringBuffer= String
                    .Join(
                    ", ",
    listInt.Select(n => n.ToString(CultureInfo.InvariantCulture))
    .ToArray()
    );
    print(stringBuffer);

    List<Int32> listInt2= stringBuffer
    .Split(',')
    .Select(c => Int32.Parse(c, CultureInfo.InvariantCulture));
    print(listInt2[0]);
}
}

这应该可以解决这个问题:

List<Int32> listInt2 = stringBuffer
            .Split(',')
            .Select(c => Int32.Parse(c, CultureInfo.InvariantCulture)).ToList();
而不是:

List<Int32> listInt2 = stringBuffer
    .Split(',')
    .Select(c => Int32.Parse(c, CultureInfo.InvariantCulture));

我不知道我怎么会错过。非常感谢。