-1

I'm attempting to convert a list of numbers to a string and then later back to a list. Converting to a string works fine, but when I convert it back to the list, I get the error "Cannot implicitly convert type 'System.Collections.Generic.IEnumerable'. This is the code I am running.

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]);
}
}
Jessica
  • 27
  • 1
  • 7

1 Answers1

0

This should resolve the issue :

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

instead of :

List<Int32> listInt2 = stringBuffer
    .Split(',')
    .Select(c => Int32.Parse(c, CultureInfo.InvariantCulture));
YouneS
  • 390
  • 4
  • 10