I’m looking for converting this list to an array so I can output specific strings from there. How could I do this? Here is the code:
public override void Select()
{
StringBuilder sb = new StringBuilder($"{MenuText()}{Environment.NewLine}");
int i = 1;
foreach (string file in _reader.paths)
{
sb.AppendLine($"{i}. {file}");
i++;
}
Console.WriteLine(sb.ToString());
int selectedIndex = ConsoleHelpers.GetIntegerInRange(1, _reader.paths.Count, MenuText()) - 1;
string[] result = File.ReadAllLines(_reader.paths[selectedIndex]);
if (result.Length == 0)
{
Console.WriteLine("Cannot open file - No data found");
}
else if (result.Length > 0)
{
var splitedStringList = new List<List<String>>();
foreach (string file in result)
{
var tmp = file.Split(':').Select(s => s.Trim()).ToArray();
splitedStringList.Add(tmp.Where(x => !string.IsNullOrEmpty(x)).ToList());
}
}
}
I tried using ‘.ToArray’ at the end of the list, but that didn’t seem to work.
New contributor
Legois is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.