I am trying to read a text file that has multiple records. Below is the code that I am using which works fine. But the problem is, if the text file contains millions of records, then it might cause out of memory exception. Can someone help me how I can modify this code to handle millions of records from the text file?
        public List<Test> ExtractDataFromFile(string filePath)
        {
            var rsltData = new List<string>();
            foreach (var line in File.ReadLines(filePath))
            {
                if (!string.IsNullOrWhiteSpace(line))
                {
                    var data = line.Split('|');
                    foreach (var item in data)
                    {
                        rsltData.Add(item);
                    }
                }
            }
         }
 
    