When it comes to the LINQ prefix, I usually write a simple loop, and Resharper will offer better LINQ optimizations, for example.
foreach (var split in File.ReadAllLines(inputFilePath).Select(l => l.Split('|'))) yield return new FindReplacePair { Find = split[0], Replace = split[1] };
R # converts it to
return File.ReadAllLines(inputFilePath).Select(l => l.Split('|')).Select(split => new FindReplacePair { Find = split[0], Replace = split[1] });
However, you can use the built-in type, for example. .ToDictionary(l => l[0], l => l[1]) or add a method on FindReplacePair , i.e.
return File.ReadAllLines(inputFilePath).Select(l => l.Split('|')).Select(FindReplacePair.Create); public static FindReplacePair Create(string[] split) { return new FindReplacePair { Find = split.First(), Replace = split.Last() }; }
source share