[SOLVED] Cannot implicitly convert type 'System.Collections.GEnric.List<Trial>' to 'Trial'

[SOLVED]
I have CSV file filled with data that I read in a script and store in a dynamic array.
I’m having trouble with a method (getNextTrial) where I can go to the next line of data in the list and may extract to change the weather or scene in my game for example.

public class Trial
{
    public int TrialNum;
    public string status;
    public string weather;
    public int time;
    public int duration;
    public string scene;
    public string displayType;
    public string InputType;


}

public class FollowTrial : MonoBehaviour
    {
        public static FollowTrial instance;
        public string path;


    public static class ExpTrials {

        private static List<Trial> trialList;
        private static int counter;
        private static Trial t;

        public class ReadCSV : MonoBehaviour //reads data and populates list
        {


            public static List<Trial> ParseFromString(string file_contents)
            {
                //List<Trial> Trials = new List<Trial>();
                string[] row = file_contents.Split('\n');

                for (int i = 1; i < row.Length; i++)
                {
                    string[] column = row[i].Split(',');
                    Trial t = new Trial();

                    int.TryParse(column[0], out t.TrialNum);
                    t.status = column[1];
                    t.weather = column[2];
                    int.TryParse(column[3], out t.time);
                    int.TryParse(column[4], out t.duration);
                    t.scene = column[5];
                    t.displayType = column[6];
                    t.InputType = column[7];

                   trialList.Add(t);
                }

                counter = 0;
                return trialList;
            }

        }

        public static Trial getNextTrial(List<Trial> t)
        {
            t = trialList[counter] ;// get trial from list and store at t
            trialList.RemoveAt(counter); //remove trial from list
            counter++;
          
            return t;
        }

Thank you in advanced.

your problem is here:

        public static Trial getNextTrial(List<Trial> t)
        {
            t = trialList[counter] ;// get trial from list and store at t

‘trialList’ is a list of objects of type Trial. So when you say ‘trialList[counter]’ you’re returning a ‘Trial’ object. But ‘t’ is a variable of type ‘List’.

You’re assigning a Trial to a variable of type List.

Those are not the same types.

Hence the error:

The error says exactly what the problem is… can’t convert between those 2 types.

It also doesn’t help you have a class level field named ‘t’ of type ‘Trial’, and a parameter named ‘t’ of type ‘List’ which probably adds even more confusion to the code.

I’m also noticing you have another variable in ‘ParseFromString’ also named ‘t’… also unnecessarily nested classes… and in general your code is just very confusing to read. It should be pointed out that short variable names like ‘t’ are usually frowned upon for this very reason.

Oh wow, realized what I needed to do lol

public static Trial getNextTrial()
        {
            currentTrial = trialList[counter] ;// get trial from list and store at t
            trialList.RemoveAt(counter); //remove trial from list
            counter++;
           
            return currentTrial;
        }

Ty!!